Merge pull request #937 from lucas-clemente/fix-server-close-race

fix race condition when closing the server
This commit is contained in:
Marten Seemann
2017-11-07 10:49:33 +07:00
committed by GitHub

View File

@@ -194,11 +194,11 @@ func (s *server) Close() error {
for _, session := range s.sessions { for _, session := range s.sessions {
if session != nil { if session != nil {
wg.Add(1) wg.Add(1)
go func() { go func(sess packetHandler) {
// session.Close() blocks until the CONNECTION_CLOSE has been sent and the run-loop has stopped // session.Close() blocks until the CONNECTION_CLOSE has been sent and the run-loop has stopped
_ = session.Close(nil) _ = sess.Close(nil)
wg.Done() wg.Done()
}() }(session)
} }
} }
s.sessionsMutex.Unlock() s.sessionsMutex.Unlock()