Skip to content

Commit

Permalink
fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Oct 20, 2024
1 parent e05522c commit 7d42518
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,17 @@ func (c *Client) moveToClosed() {
})
}

c.mu.Lock()
defer c.mu.Unlock()
c.mu.RLock()
disconnectedCh := c.disconnectedCh
c.mu.RUnlock()
// At this point connection close was issued, so we wait until the reader goroutine
// finishes its work, after that it's safe to close the callback queue.
if c.disconnectedCh != nil {
<-c.disconnectedCh
if disconnectedCh != nil {
<-disconnectedCh
}

c.mu.Lock()
defer c.mu.Unlock()
c.disconnectedCh = nil
c.cbQueue.close()
c.cbQueue = nil
Expand Down

0 comments on commit 7d42518

Please sign in to comment.