From 9e09dffbc3509a3abcbb88f738f7a5264ea99675 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 14 Aug 2020 19:27:36 +0300 Subject: [PATCH] - dns: limit the number of active goroutines for incoming requests processing Close #2015 Squashed commit of the following: commit 90ba06f1fce22a452b4d61db62bd950b976debd1 Merge: 9494b29b 473d8818 Author: Simon Zolin Date: Fri Aug 14 19:14:26 2020 +0300 Merge remote-tracking branch 'origin/master' into max-go commit 9494b29b65ae8fe593a487984bed051aa78e4ff9 Author: Simon Zolin Date: Fri Aug 14 17:03:00 2020 +0300 + max_goroutines setting commit 87071a5e0ed43be192a7755fb25764cd4519da5a Author: Simon Zolin Date: Fri Aug 14 15:29:00 2020 +0300 - dns: limit the number of active goroutines for incoming requests processing --- dnsforward/config.go | 2 ++ dnsforward/dnsforward.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/dnsforward/config.go b/dnsforward/config.go index 24ed3f7f..db0033c1 100644 --- a/dnsforward/config.go +++ b/dnsforward/config.go @@ -81,6 +81,7 @@ type FilteringConfig struct { AAAADisabled bool `yaml:"aaaa_disabled"` // Respond with an empty answer to all AAAA requests EnableDNSSEC bool `yaml:"enable_dnssec"` // Set DNSSEC flag in outcoming DNS request EnableEDNSClientSubnet bool `yaml:"edns_client_subnet"` // Enable EDNS Client Subnet option + MaxGoroutines uint32 `yaml:"max_goroutines"` // Max. number of parallel goroutines for processing incoming requests } // TLSConfig is the TLS configuration for HTTPS, DNS-over-HTTPS, and DNS-over-TLS @@ -144,6 +145,7 @@ func (s *Server) createProxyConfig() (proxy.Config, error) { BeforeRequestHandler: s.beforeRequestHandler, RequestHandler: s.handleDNSRequest, EnableEDNSClientSubnet: s.conf.EnableEDNSClientSubnet, + MaxGoroutines: int(s.conf.MaxGoroutines), } if s.conf.CacheSize != 0 { diff --git a/dnsforward/dnsforward.go b/dnsforward/dnsforward.go index 36f5445e..95db8967 100644 --- a/dnsforward/dnsforward.go +++ b/dnsforward/dnsforward.go @@ -176,6 +176,9 @@ func (s *Server) Prepare(config *ServerConfig) error { return fmt.Errorf("DNS: invalid custom blocking IP address specified") } } + if s.conf.MaxGoroutines == 0 { + s.conf.MaxGoroutines = 50 + } } // 2. Set default values in the case if nothing is configured