Skip to content

Commit

Permalink
Increasing nofiles limit on UNIX systems
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Jul 7, 2016
1 parent 79a537b commit 40c1734
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/github.com/getlantern/flashlight/main/increase_nofiles.go
@@ -0,0 +1,34 @@
// +build !windows

package main

import (
"syscall"
)

const (
// 1024 is the default hard limit on Ubuntu, so let's not get greedier than
// that. On OS X, the default hard limit is unlimited.
DesiredNoFilesLimit = 1024
)

func init() {
// We increase the nofiles limit on UNIX platforms to avoid running out of
// file descriptors
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Errorf("Error getting nofiles limit %v", err)
return
}
if rLimit.Cur > DesiredNoFilesLimit {
log.Debugf("Current nofiles soft limit of %d is enough", rLimit.Cur)
return
}
rLimit.Cur = DesiredNoFilesLimit
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Errorf("Unable to increase nofiles limit: %v", err)
}
log.Debugf("Changed nofiles soft limit to %d", rLimit.Cur)
}

0 comments on commit 40c1734

Please sign in to comment.