From 1755a2e88d74dbcbf1c108a25ff61640f9cb8baf Mon Sep 17 00:00:00 2001 From: 0x1a8510f2 Date: Mon, 12 Sep 2022 15:29:04 +0100 Subject: [PATCH] Don't raise fd limit + simplify build constraints --- setup/base/sanity_other.go | 4 ++-- setup/base/sanity_unix.go | 34 +++++----------------------------- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/setup/base/sanity_other.go b/setup/base/sanity_other.go index 48fe6e1f8..56c1183c4 100644 --- a/setup/base/sanity_other.go +++ b/setup/base/sanity_other.go @@ -1,5 +1,5 @@ -//go:build !linux && !darwin && !netbsd && !freebsd && !openbsd && !solaris && !dragonfly && !aix -// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!solaris,!dragonfly,!aix +//go:build !unix +// +build !unix package base diff --git a/setup/base/sanity_unix.go b/setup/base/sanity_unix.go index c630d3f19..f655bd40b 100644 --- a/setup/base/sanity_unix.go +++ b/setup/base/sanity_unix.go @@ -1,35 +1,11 @@ -//go:build linux || darwin || netbsd || freebsd || openbsd || solaris || dragonfly || aix -// +build linux darwin netbsd freebsd openbsd solaris dragonfly aix +//go:build unix +// +build unix package base -import ( - "syscall" - - "github.com/sirupsen/logrus" -) +// OS import to automatically raise file descriptor limit. +import _ "os" 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) - } - } + // Nothing to do yet. }