Merge pull request #1445 from lucas-clemente/fix-1444

fix race condition when adding packet handlers to the multiplexer
This commit is contained in:
Marten Seemann 2018-07-06 15:29:34 +07:00 committed by GitHub
commit 2bc5b7f532
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,6 +56,7 @@ func getClientMultiplexer() multiplexer {
func (m *clientMultiplexer) AddConn(c net.PacketConn, connIDLen int) (packetHandlerManager, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
p, ok := m.conns[c]
if !ok {
manager := m.newPacketHandlerManager()
@ -72,6 +73,9 @@ func (m *clientMultiplexer) AddConn(c net.PacketConn, connIDLen int) (packetHand
}
func (m *clientMultiplexer) AddHandler(c net.PacketConn, connID protocol.ConnectionID, handler packetHandler) error {
m.mutex.Lock()
defer m.mutex.Unlock()
p, ok := m.conns[c]
if !ok {
return errors.New("unknown packet conn %s")