From d578c713ff5eebb73ba93520dc429fde86869afc Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Tue, 26 Nov 2024 13:34:16 +0300 Subject: [PATCH] Pull request 2310: 6818-fix-goroutine-leak Updates #6818. Squashed commit of the following: commit 3027fc4a615beba9138449d65994f1630b5a6cbf Author: Stanislav Chzhen Date: Mon Nov 25 16:53:33 2024 +0300 all: fixed goroutine leak --- CHANGELOG.md | 6 ++++++ internal/dnsforward/dnsforward.go | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b260d138..52053e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,12 @@ NOTE: Add new changes BELOW THIS COMMENT. permissions for the security-sensitive files and directories, which caused issues on Windows ([#7400]). +### Fixed + +- Goroutine leak during configuration update resulting in increased response + time. ([#6818]). + +[#6818]: https://github.com/AdguardTeam/AdGuardHome/issues/6818 [#7400]: https://github.com/AdguardTeam/AdGuardHome/issues/7400 [go-1.23.3]: https://groups.google.com/g/golang-announce/c/X5KodEJYuqI diff --git a/internal/dnsforward/dnsforward.go b/internal/dnsforward/dnsforward.go index 107eea39..27037234 100644 --- a/internal/dnsforward/dnsforward.go +++ b/internal/dnsforward/dnsforward.go @@ -818,6 +818,8 @@ func (s *Server) proxy() (p *proxy.Proxy) { } // Reconfigure applies the new configuration to the DNS server. +// +// TODO(a.garipov): This whole piece of API is weird and needs to be remade. func (s *Server) Reconfigure(conf *ServerConfig) error { s.serverLock.Lock() defer s.serverLock.Unlock() @@ -831,14 +833,15 @@ func (s *Server) Reconfigure(conf *ServerConfig) error { // We wait for some time and hope that this fd will be closed. time.Sleep(100 * time.Millisecond) - // TODO(a.garipov): This whole piece of API is weird and needs to be remade. + if s.addrProc != nil { + err := s.addrProc.Close() + if err != nil { + log.Error("dnsforward: closing address processor: %s", err) + } + } + if conf == nil { conf = &s.conf - } else { - closeErr := s.addrProc.Close() - if closeErr != nil { - log.Error("dnsforward: closing address processor: %s", closeErr) - } } // TODO(e.burkov): It seems an error here brings the server down, which is