mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 11:41:38 +00:00
Attempt to raise the file descriptor limit at startup (#2527)
This commit is contained in:
parent
1030072285
commit
89d2adadbd
@ -15,8 +15,21 @@ func platformSanityChecks() {
|
|||||||
// If we run out of file descriptors, we might run into problems accessing
|
// If we run out of file descriptors, we might run into problems accessing
|
||||||
// PostgreSQL amongst other things. Complain at startup if we think the
|
// PostgreSQL amongst other things. Complain at startup if we think the
|
||||||
// number of file descriptors is too low.
|
// number of file descriptors is too low.
|
||||||
var rLimit syscall.Rlimit
|
warn := func(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)
|
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 {
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user