diff options
| author | Shulhan <ms@kilabit.info> | 2019-06-24 23:52:05 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-06-24 23:52:05 +0700 |
| commit | dada906a238c080333c1d6483ab7c1b3f0fe849b (patch) | |
| tree | 27062435c8c746353eae6a4372e9e24238bb8b1a | |
| parent | 2516d2d69c5535a50fc72403066b95a86bf225a4 (diff) | |
| download | pakakeh.go-dada906a238c080333c1d6483ab7c1b3f0fe849b.tar.xz | |
dns: recreate the DoH forwarder when query fail
When query with DoH forwarder return an error, we assume that there is
a problem with the connection. To mitigate the problem when subsequent
query using broken connection return an error, we close the forwarder
connection and create a new one.
| -rw-r--r-- | lib/dns/server.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/dns/server.go b/lib/dns/server.go index df6a728d..cc224e2c 100644 --- a/lib/dns/server.go +++ b/lib/dns/server.go @@ -700,6 +700,8 @@ func (srv *Server) runForwarders() { } func (srv *Server) runDohForwarder(nameserver string, primaryq, fallbackq chan *request) { + var isSuccess bool + srv.fwGroup.Add(1) log.Printf("dns: starting DoH forwarder at %s", nameserver) @@ -709,7 +711,8 @@ func (srv *Server) runDohForwarder(nameserver string, primaryq, fallbackq chan * log.Fatal("dns: failed to create DoH forwarder: " + err.Error()) } - for srv.isForwarding { //nolint:gosimple + isSuccess = true + for srv.isForwarding && isSuccess { //nolint:gosimple select { case req, ok := <-primaryq: if !ok { @@ -727,12 +730,18 @@ func (srv *Server) runDohForwarder(nameserver string, primaryq, fallbackq chan * if fallbackq != nil { fallbackq <- req } - continue + isSuccess = false + } else { + srv.processResponse(req, res, fallbackq) } - - srv.processResponse(req, res, fallbackq) } } + + forwarder.Close() + + if srv.isForwarding { + log.Println("dns: restarting DoH forwarder for " + nameserver) + } } out: srv.fwGroup.Done() |
