Pull request: 5052 Close errors

Merge in DNS/adguard-home from 5052-nonfatal-close to master

Updates #5052.

Squashed commit of the following:

commit 8411de465a29517640556e7d2390059482e01e8a
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Oct 20 16:54:52 2022 +0300

    dnsforward: imp code

commit d6dff964397d6d878267f24b844bc6040edec316
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Oct 20 16:48:55 2022 +0300

    dnsforward: revert tmp stuff

commit 519aaf21cd1929141ea1902388d40599dced55ea
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Oct 20 16:28:32 2022 +0300

    dnsforward: fix ups closing errors
This commit is contained in:
Eugene Burkov 2022-10-20 18:22:37 +03:00
parent 2de42284a5
commit 68d13fcc2b
1 changed files with 22 additions and 10 deletions

View File

@ -560,31 +560,43 @@ func (s *Server) Stop() error {
// stopLocked stops the DNS server without locking. For internal use only.
func (s *Server) stopLocked() (err error) {
var errs []error
if s.dnsProxy != nil {
err = s.dnsProxy.Stop()
if err != nil {
errs = append(errs, fmt.Errorf("could not stop primary resolvers properly: %w", err))
return fmt.Errorf("closing primary resolvers: %w", err)
}
}
if s.internalProxy != nil && s.internalProxy.UpstreamConfig != nil {
err = s.internalProxy.UpstreamConfig.Close()
var errs []error
if upsConf := s.internalProxy.UpstreamConfig; upsConf != nil {
const action = "closing internal resolvers"
err = upsConf.Close()
if err != nil {
errs = append(errs, fmt.Errorf("could not stop internal resolvers properly: %w", err))
if errors.Is(err, net.ErrClosed) {
log.Debug("dnsforward: %s: %s", action, err)
} else {
errs = append(errs, fmt.Errorf("%s: %w", action, err))
}
}
}
if s.localResolvers != nil && s.localResolvers.UpstreamConfig != nil {
err = s.localResolvers.UpstreamConfig.Close()
if upsConf := s.localResolvers.UpstreamConfig; upsConf != nil {
const action = "closing local resolvers"
err = upsConf.Close()
if err != nil {
errs = append(errs, fmt.Errorf("could not stop local resolvers properly: %w", err))
if errors.Is(err, net.ErrClosed) {
log.Debug("dnsforward: %s: %s", action, err)
} else {
errs = append(errs, fmt.Errorf("%s: %w", action, err))
}
}
}
if len(errs) > 0 {
return errors.List("stopping DNS server", errs...)
return errors.List("stopping dns server", errs...)
} else {
s.isRunning = false
}