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:
Olaoluwa Osuntokun 2018-05-03 15:45:22 -07:00
parent f7c5a7a19e
commit 5f059e74cb
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -637,6 +637,7 @@ func (ms *msgStream) msgConsumer() {
select {
case ms.producerSema <- struct{}{}:
case <-ms.quit:
atomic.StoreInt32(&ms.streamShutdown, 1)
return
}
}