From 8b9662924f030867c07230fe4a852e384a83a5b2 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 6 Jul 2018 12:03:54 +0700 Subject: [PATCH] fix race condition when adding packet handlers to the multiplexer --- client_multiplexer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client_multiplexer.go b/client_multiplexer.go index 4b7c7ecf..9784e01b 100644 --- a/client_multiplexer.go +++ b/client_multiplexer.go @@ -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")