From 1f1e26f67b00ee4983c65e4e3aabf59a488f687b Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Wed, 27 Mar 2019 17:09:48 +0300 Subject: [PATCH] + config: add "rlimit_nofile" setting - Maximum number of opened fd's per process --- app.go | 17 +++++++++++++++++ config.go | 12 +++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app.go b/app.go index ba8aee3c..8484b553 100644 --- a/app.go +++ b/app.go @@ -92,6 +92,11 @@ func run(args options) { log.Fatal(err) } + if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && + config.RlimitNoFile != 0 { + setRlimit(config.RlimitNoFile) + } + // override bind host/port from the console if args.bindHost != "" { config.BindHost = args.bindHost @@ -285,6 +290,18 @@ func enableTLS13() { } } +// Set user-specified limit of how many fd's we can use +// https://github.com/AdguardTeam/AdGuardHome/issues/659 +func setRlimit(val uint) { + var rlim syscall.Rlimit + rlim.Max = uint64(val) + rlim.Cur = uint64(val) + err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) + if err != nil { + log.Error("Setrlimit() failed: %v", err) + } +} + func cleanup() { log.Info("Stopping AdGuard Home") diff --git a/config.go b/config.go index 07466925..14ea6677 100644 --- a/config.go +++ b/config.go @@ -34,11 +34,13 @@ type configuration struct { ourWorkingDir string // Location of our directory, used to protect against CWD being somewhere else firstRun bool // if set to true, don't run any services except HTTP web inteface, and serve only first-run html - BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to - BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server - AuthName string `yaml:"auth_name"` // AuthName is the basic auth username - AuthPass string `yaml:"auth_pass"` // AuthPass is the basic auth password - Language string `yaml:"language"` // two-letter ISO 639-1 language code + BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to + BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server + AuthName string `yaml:"auth_name"` // AuthName is the basic auth username + AuthPass string `yaml:"auth_pass"` // AuthPass is the basic auth password + Language string `yaml:"language"` // two-letter ISO 639-1 language code + RlimitNoFile uint `yaml:"rlimit_nofile"` // Maximum number of opened fd's per process (0: default) + DNS dnsConfig `yaml:"dns"` TLS tlsConfig `yaml:"tls"` Filters []filter `yaml:"filters"`