fix race condition when closing the server after a Read failed

This commit is contained in:
Marten Seemann
2019-05-10 09:47:52 +09:00
parent c135b4f1e3
commit dc75123836
4 changed files with 21 additions and 26 deletions

View File

@@ -141,7 +141,6 @@ func (h *packetHandlerMap) close(e error) error {
h.mutex.Unlock()
return nil
}
h.closed = true
var wg sync.WaitGroup
for _, handler := range h.handlers {
@@ -153,8 +152,9 @@ func (h *packetHandlerMap) close(e error) error {
}
if h.server != nil {
h.server.closeWithError(e)
h.server.setCloseError(e)
}
h.closed = true
h.mutex.Unlock()
wg.Wait()
return getMultiplexer().RemoveConn(h.conn)