From 4397cd7fc2e3c297f4d4e85ae5e631fac346e135 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 15 Nov 2021 21:22:43 +0100 Subject: [PATCH] cmd/soju: bump max number of opened files The bouncer process may be dealing with many opened FDs. The default on Linux is 1024. To support bouncers with a lot of users, bump RLIMIT_NOFILE to the max as advised in [1]. [1]: http://0pointer.net/blog/file-descriptor-limits.html --- cmd/soju/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/soju/main.go b/cmd/soju/main.go index f8626f0..186573e 100644 --- a/cmd/soju/main.go +++ b/cmd/soju/main.go @@ -50,6 +50,18 @@ func loadMOTD(srv *soju.Server, filename string) error { return nil } +func bumpOpenedFileLimit() error { + var rlimit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { + return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err) + } + rlimit.Cur = rlimit.Max + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { + return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err) + } + return nil +} + func main() { var listen []string var configPath string @@ -75,6 +87,10 @@ func main() { cfg.Listen = []string{":6697"} } + if err := bumpOpenedFileLimit(); err != nil { + log.Printf("failed to bump max number of opened files: %v", err) + } + db, err := soju.OpenDB(cfg.SQLDriver, cfg.SQLSource) if err != nil { log.Fatalf("failed to open database: %v", err)