mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-22 06:11:55 -06:00
46902e5766
Given that #2714 wasn't merged but we are now at a minimum supported Go version of 1.20 (soon to be 1.21), I wanted to carry over some of the changes. Namely: - Fix the log typo - Simplify build constraints for unix - Use stdlib atomic package ### Pull Request Checklist <!-- Please read https://matrix-org.github.io/dendrite/development/contributing before submitting your pull request --> * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `0x1a8510f2 <admin@0x1a8510f2.space>` --------- Co-authored-by: devonh <devon.dmytro@gmail.com>
36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
//go:build unix
|
|
// +build unix
|
|
|
|
package base
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func PlatformSanityChecks() {
|
|
// Dendrite needs a relatively high number of file descriptors in order
|
|
// 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)
|
|
}
|
|
}
|
|
}
|