Skip to content

Commit

Permalink
Merge pull request #2864 from lucas-clemente/packet-handler-map-mutex…
Browse files Browse the repository at this point in the history
…-type

replace the RWMutex with a Mutex in the packet handler map
  • Loading branch information
marten-seemann authored Nov 11, 2020
2 parents 3cd8b30 + ba37b0e commit 0bd10a6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packet_handler_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0bd10a6

Please sign in to comment.