Skip to content

Commit

Permalink
Merge branch 'master' into 3972-hostlists-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Oct 20, 2022
2 parents 607077c + 68d13fc commit b7f961c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b7f961c

Please sign in to comment.