diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-06-10 10:58:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-10 10:58:04 +0100 |
commit | 89d2adadbdef4ce62338d55d56b58fa58055d495 (patch) | |
tree | 16b245aada944c3d299b561d0a35c21da7ec01a5 /setup/base | |
parent | 10300722859ba345b8b21980e39a8a7022e6d35b (diff) |
Attempt to raise the file descriptor limit at startup (#2527)
Diffstat (limited to 'setup/base')
-rw-r--r-- | setup/base/sanity_unix.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/setup/base/sanity_unix.go b/setup/base/sanity_unix.go index 0c1543e0..c630d3f1 100644 --- a/setup/base/sanity_unix.go +++ b/setup/base/sanity_unix.go @@ -15,8 +15,21 @@ func platformSanityChecks() { // If we run out of file descriptors, we might run into problems accessing // PostgreSQL amongst other things. Complain at startup if we think the // number of file descriptors is too low. + warn := func(rLimit *syscall.Rlimit) { + logrus.Warnf("IMPORTANT: Process file descriptor limit is currently %d, it is recommended to raise the limit for Dendrite to at least 65535 to avoid issues", rLimit.Cur) + } var rLimit syscall.Rlimit if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err == nil && rLimit.Cur < 65535 { - logrus.Warnf("IMPORTANT: Process file descriptor limit is currently %d, it is recommended to raise the limit for Dendrite to at least 65535 to avoid issues", rLimit.Cur) + // The file descriptor count is too low. Let's try to raise it. + rLimit.Cur = 65535 + if err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { + // We failed to raise it, so log an error. + logrus.WithError(err).Warn("IMPORTANT: Failed to raise the file descriptor limit") + warn(&rLimit) + } else if err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err == nil && rLimit.Cur < 65535 { + // We think we successfully raised the limit, but a second call to + // get the limit told us that we didn't succeed. Log an error. + warn(&rLimit) + } } } |