Skip to content

Commit

Permalink
dnsforward: imp code, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Oct 6, 2021
1 parent 3a4f04f commit 5ffe519
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ In this release, the schema version has changed from 10 to 12.

### Fixed

- Panic while shutdown ([#3655]).
- Occasional panic during shutdown ([#3655]).
- Addition of IPs into only one as opposed to all matching ipsets on Linux
([#3638]).
- Removal of temporary filter files ([#3567]).
Expand Down
3 changes: 1 addition & 2 deletions internal/dnsforward/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/stringutil"
Expand Down Expand Up @@ -545,7 +544,7 @@ func (s *Server) processUpstream(ctx *dnsContext) (rc resultCode) {

prx := s.proxy()
if prx == nil {
ctx.err = errors.Error("server is closed")
ctx.err = srvClosedErr

return resultCodeError
}
Expand Down
12 changes: 7 additions & 5 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,15 @@ func (s *Server) IsRunning() bool {
return s.isRunning
}

// proxy returns the underlying *proxy.Proxy from s to be accessed in
// concurrent-safe methods. It should prevent problems caused by unexpected
// rewrites of the field inside s. It returns nil when s is stopping or already
// closed itself.
// srvClosedErr is returned when the method can't complete without unacessible
// data from the closing server.
const srvClosedErr errors.Error = "server is closed"

// proxy returns a pointer to the current DNS proxy instance. If p is nil, the
// server is closing.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/3655.
func (s *Server) proxy() (prx *proxy.Proxy) {
func (s *Server) proxy() (p *proxy.Proxy) {
s.serverLock.RLock()
defer s.serverLock.RUnlock()

Expand Down
2 changes: 1 addition & 1 deletion internal/dnsforward/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *Server) genBlockedHost(request *dns.Msg, newAddr string, d *proxy.DNSCo

prx := s.proxy()
if prx == nil {
log.Debug("dns server is closed")
log.Debug("dns: %s", srvClosedErr)

return s.genServerFailure(request)
}
Expand Down

0 comments on commit 5ffe519

Please sign in to comment.