From ba37b0e02b48906d0f2903eedd30c8ce0067b1a7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 6 Nov 2020 17:09:21 +0700 Subject: [PATCH] replace the RWMutex with a Mutex in the packet handler map --- packet_handler_map.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packet_handler_map.go b/packet_handler_map.go index a458ee98..ae542e59 100644 --- a/packet_handler_map.go +++ b/packet_handler_map.go @@ -30,7 +30,7 @@ func (e statelessResetErr) Error() string { // * by the server to store sessions // * when multiplexing outgoing connections to store clients type packetHandlerMap struct { - mutex sync.RWMutex + mutex sync.Mutex conn connection connIDLen int @@ -320,16 +320,14 @@ func (h *packetHandlerMap) handlePacket(p *receivedPacket) { return } - h.mutex.RLock() - defer h.mutex.RUnlock() + h.mutex.Lock() + defer h.mutex.Unlock() if isStatelessReset := h.maybeHandleStatelessReset(p.data); isStatelessReset { return } - handler, handlerFound := h.handlers[string(connID)] - - if handlerFound { // existing session + if handler, ok := h.handlers[string(connID)]; ok { // existing session handler.handlePacket(p) return }