mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-15 10:03:09 -06:00
Don't raise fd limit + simplify build constraints
See https://github.com/matrix-org/dendrite/issues/2564
This commit is contained in:
parent
af036a7efa
commit
d42653643f
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build !linux && !darwin && !netbsd && !freebsd && !openbsd && !solaris && !dragonfly && !aix
|
//go:build !unix
|
||||||
// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!solaris,!dragonfly,!aix
|
// +build !unix
|
||||||
|
|
||||||
package base
|
package base
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,11 @@
|
||||||
//go:build linux || darwin || netbsd || freebsd || openbsd || solaris || dragonfly || aix
|
//go:build unix
|
||||||
// +build linux darwin netbsd freebsd openbsd solaris dragonfly aix
|
// +build unix
|
||||||
|
|
||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
// OS import to automatically raise file descriptor limit
|
||||||
"syscall"
|
import _ "os"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func platformSanityChecks() {
|
func platformSanityChecks() {
|
||||||
// Dendrite needs a relatively high number of file descriptors in order
|
// Nothing to do yet.
|
||||||
// to function properly, particularly when federating with lots of servers.
|
|
||||||
// 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 {
|
|
||||||
// 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 a new issue