mirror of
https://github.com/miekg/dns.git
synced 2025-12-16 09:11:34 +01:00
Fix TCP Shutdown 'use of closed network connection' (#623)
The check for srv.started being false is in the wrong place, it should be after Accept not after ReadTCP. If Shutdown is called, serveTCP will currently return a 'use of closed network connection' error, which is undesired. This commit mirrors the behaviour of serveUDP with respect to Shutdown.
This commit is contained in:
parent
9cef7a0d3d
commit
f5ac34d755
12
server.go
12
server.go
@ -460,6 +460,12 @@ func (srv *Server) serveTCP(l net.Listener) error {
|
|||||||
// deadline is not used here
|
// deadline is not used here
|
||||||
for {
|
for {
|
||||||
rw, err := l.Accept()
|
rw, err := l.Accept()
|
||||||
|
srv.lock.RLock()
|
||||||
|
if !srv.started {
|
||||||
|
srv.lock.RUnlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
srv.lock.RUnlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if neterr, ok := err.(net.Error); ok && neterr.Temporary() {
|
if neterr, ok := err.(net.Error); ok && neterr.Temporary() {
|
||||||
continue
|
continue
|
||||||
@ -467,12 +473,6 @@ func (srv *Server) serveTCP(l net.Listener) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m, err := reader.ReadTCP(rw, rtimeout)
|
m, err := reader.ReadTCP(rw, rtimeout)
|
||||||
srv.lock.RLock()
|
|
||||||
if !srv.started {
|
|
||||||
srv.lock.RUnlock()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
srv.lock.RUnlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user