diff options
| author | Shulhan <ms@kilabit.info> | 2019-06-24 23:52:33 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-06-24 23:52:33 +0700 |
| commit | 7cd0290b065ea9f6a09bd180aeafd8f113b7c617 (patch) | |
| tree | f7e11971624cb71ce4f77617c24b3cba3d1178e4 | |
| parent | dada906a238c080333c1d6483ab7c1b3f0fe849b (diff) | |
| download | pakakeh.go-7cd0290b065ea9f6a09bd180aeafd8f113b7c617.tar.xz | |
dns: replace goto with boolean condition for restarting UDP forwarder
| -rw-r--r-- | lib/dns/server.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/dns/server.go b/lib/dns/server.go index cc224e2c..7788eaf2 100644 --- a/lib/dns/server.go +++ b/lib/dns/server.go @@ -793,6 +793,8 @@ out: // and forward it to parent server at "remoteAddr". // func (srv *Server) runUDPForwarder(remoteAddr string, primaryq, fallbackq chan *request) { + var isSuccess bool + srv.fwGroup.Add(1) log.Printf("dns: starting UDP forwarder at %s", remoteAddr) @@ -803,8 +805,10 @@ func (srv *Server) runUDPForwarder(remoteAddr string, primaryq, fallbackq chan * log.Fatal("dns: failed to create UDP forwarder: " + err.Error()) } + isSuccess = true + // The second loop consume the forward queue. - for srv.isForwarding { //nolint:gosimple + for srv.isForwarding && isSuccess { //nolint:gosimple select { case req, ok := <-primaryq: if !ok { @@ -822,13 +826,13 @@ func (srv *Server) runUDPForwarder(remoteAddr string, primaryq, fallbackq chan * if fallbackq != nil { fallbackq <- req } - goto brokenClient + isSuccess = false + } else { + srv.processResponse(req, res, fallbackq) } - - srv.processResponse(req, res, fallbackq) } } - brokenClient: + forwarder.Close() if srv.isForwarding { |
