Skip to content

Commit 2d43288

Browse files
committed
main: increase open file limit to 4096
Linux by default has a soft limit of 1024 and a hard limit of 4096 on open files. We can increase it so 4096 without root permissions. This should help reduce the risk of gocryptfs running out of file descriptors, as reported at #82 .
1 parent daada9d commit 2d43288

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mount.go

+12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ func doMount(args *argContainer) int {
147147
// Send SIGUSR1 to our parent
148148
sendUsr1(args.notifypid)
149149
}
150+
// Increase the number of open files limit up to the hard limit. It's not
151+
// dramatic if that fails, so do it after we have switched to syslog and not
152+
// bother the user with warning.
153+
var lim syscall.Rlimit
154+
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
155+
lim.Cur = lim.Max
156+
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
157+
if err != nil {
158+
tlog.Warn.Printf("Setting RLIMIT_NOFILE failed: %v", err)
159+
} else if lim.Cur < 4096 {
160+
tlog.Warn.Printf("Low hard limit for RLIMIT_NOFILE: %d", lim.Cur)
161+
}
150162
// Wait for SIGINT in the background and unmount ourselves if we get it.
151163
// This prevents a dangling "Transport endpoint is not connected"
152164
// mountpoint if the user hits CTRL-C.

0 commit comments

Comments
 (0)