diff options
author | 2017-02-19 20:34:09 +0000 | |
---|---|---|
committer | 2017-02-19 20:34:09 +0000 | |
commit | bcd9c8b0fb83c4da4d84a2bafb1d1f8275b49b49 (patch) | |
tree | 2ea305a7ca9fb76779b0e4d6837af54784057c3b | |
parent | 5aa30308d9567e77b1176d64f6383c6525347699 (diff) | |
download | coredns-bcd9c8b0fb83c4da4d84a2bafb1d1f8275b49b49.tar.gz coredns-bcd9c8b0fb83c4da4d84a2bafb1d1f8275b49b49.tar.zst coredns-bcd9c8b0fb83c4da4d84a2bafb1d1f8275b49b49.zip |
server: fix data race (#536)
* server: fix data race
This fixes the detected race.
Fixes #534
* Remove the listener and packetconn from Server
There does not seem a need to store the listener and packetconn again
in the Server structure. The dns.Servers already has access to them
and can also shutdown the handlers.
-rw-r--r-- | core/dnsserver/server.go | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/core/dnsserver/server.go b/core/dnsserver/server.go index 2d018ecc7..a112e4f5b 100644 --- a/core/dnsserver/server.go +++ b/core/dnsserver/server.go @@ -25,13 +25,11 @@ import ( // the same address and the listener may be stopped for // graceful termination (POSIX only). type Server struct { - Addr string // Address we listen on - mux *dns.ServeMux - server [2]*dns.Server // 0 is a net.Listener, 1 is a net.PacketConn (a *UDPConn) in our case. + Addr string // Address we listen on + mux *dns.ServeMux - l net.Listener - p net.PacketConn - m sync.Mutex // protects listener and packetconn + server [2]*dns.Server // 0 is a net.Listener, 1 is a net.PacketConn (a *UDPConn) in our case. + m sync.Mutex // protects the servers zones map[string]*Config // zones keyed by their address dnsWg sync.WaitGroup // used to wait on outstanding connections @@ -99,9 +97,6 @@ func (s *Server) Listen() (net.Listener, error) { if err != nil { return nil, err } - s.m.Lock() - s.l = l - s.m.Unlock() return l, nil } @@ -112,9 +107,6 @@ func (s *Server) ListenPacket() (net.PacketConn, error) { return nil, err } - s.m.Lock() - s.p = p - s.m.Unlock() return p, nil } @@ -145,13 +137,6 @@ func (s *Server) Stop() (err error) { // Close the listener now; this stops the server without delay s.m.Lock() - if s.l != nil { - err = s.l.Close() - } - if s.p != nil { - err = s.p.Close() - } - for _, s1 := range s.server { // We might not have started and initialized the full set of servers if s1 != nil { |