From 759013750f98f80739bc531d267f9ee3e4322aa9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 3 Feb 2022 10:27:16 +0100 Subject: [PATCH] Bump RLIMIT_NOFILE We're a TCP server, we'll handle potentially a lot of FDs. See https://0pointer.net/blog/file-descriptor-limits.html --- cmd/tlstunnel/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/tlstunnel/main.go b/cmd/tlstunnel/main.go index c9d2e64..d99652a 100644 --- a/cmd/tlstunnel/main.go +++ b/cmd/tlstunnel/main.go @@ -54,10 +54,26 @@ func newServer() (*tlstunnel.Server, error) { return srv, 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() { flag.StringVar(&configPath, "config", configPath, "path to configuration file") flag.Parse() + if err := bumpOpenedFileLimit(); err != nil { + log.Printf("failed to bump max number of opened files: %v", err) + } + srv, err := newServer() if err != nil { log.Fatalf("failed to create server: %v", err)