Skip to content

Commit

Permalink
Fix deadlock when handling socket disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed May 22, 2024
1 parent 74a5063 commit 0b5cd1e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions messagix/responsehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ func (p *ResponseHandler) getChannel(packetId uint16, channelType ChannelType) (
func (p *ResponseHandler) CancelAllRequests() {
p.lock.Lock()
defer p.lock.Unlock()
for packetId := range p.requestChannels {
p.deleteDetails(packetId, RequestChannel)
for _, ch := range p.requestChannels {
close(ch)
}
for packetId := range p.packetChannels {
p.deleteDetails(packetId, PacketChannel)
for _, ch := range p.packetChannels {
close(ch)
}
p.requestChannels = make(map[uint16]chan any)
p.packetChannels = make(map[uint16]chan any)
}

0 comments on commit 0b5cd1e

Please sign in to comment.