peer: ensure msgConsumer sets the shutdown variable on exit
In this commit, we fix a bug that could at times cause a deadlock when a peer is attempting to disconnect. The issue was that when a peer goes to disconnect, it needs to stop any active msgStream instances. The Stop() method of the msgStream would block until an atomic variable was set to indicate that the stream had fully exited. However, in the case that we disconnected lower in the msgConsumer loop, we would never set the streamShutdown variable, meaning that msgStream.Stop() would never unblock. The fix for this is simple: set the streamShutdown variable within the quit case of the second select statement in the msgConsumer goroutine.
This commit is contained in:
parent
f7c5a7a19e
commit
5f059e74cb
1
peer.go
1
peer.go
@ -637,6 +637,7 @@ func (ms *msgStream) msgConsumer() {
|
||||
select {
|
||||
case ms.producerSema <- struct{}{}:
|
||||
case <-ms.quit:
|
||||
atomic.StoreInt32(&ms.streamShutdown, 1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user