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:
Tom Thorogood 2018-01-11 00:07:59 +10:30 committed by Miek Gieben
parent 9cef7a0d3d
commit f5ac34d755
1 changed files with 6 additions and 6 deletions

View File

@ -460,6 +460,12 @@ func (srv *Server) serveTCP(l net.Listener) error {
// deadline is not used here
for {
rw, err := l.Accept()
srv.lock.RLock()
if !srv.started {
srv.lock.RUnlock()
return nil
}
srv.lock.RUnlock()
if err != nil {
if neterr, ok := err.(net.Error); ok && neterr.Temporary() {
continue
@ -467,12 +473,6 @@ func (srv *Server) serveTCP(l net.Listener) error {
return err
}
m, err := reader.ReadTCP(rw, rtimeout)
srv.lock.RLock()
if !srv.started {
srv.lock.RUnlock()
return nil
}
srv.lock.RUnlock()
if err != nil {
continue
}