Skip to content

Commit

Permalink
fix: avoid race condition on shutdown during handshake
Browse files Browse the repository at this point in the history
We don't need to close handshakeFinishedChan, since the only place we
wait on it also is watching for doneChan to be closed
  • Loading branch information
agaffney committed Feb 12, 2024
1 parent 08f69ad commit 6e44819
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,6 @@ func (c *Connection) shutdown() {
c.waitGroup.Wait()
// Close consumer error channel to signify connection shutdown
close(c.errorChan)
// We can only close a channel once, so we have to jump through a few hoops
select {
// The channel is either closed or has an item pending
case _, ok := <-c.handshakeFinishedChan:
// We successfully retrieved an item
// This will probably never happen, but it doesn't hurt to cover this case
if ok {
close(c.handshakeFinishedChan)
}
// The channel is open and has no pending items
default:
close(c.handshakeFinishedChan)
}
}

// setupConnection establishes the muxer, configures and starts the handshake process, and initializes
Expand Down

0 comments on commit 6e44819

Please sign in to comment.