peer: ensure queueMsg won't create deadlock if peer shutting down

This commit adds some additional measures to ensure that a call to
queueMsg while the peer is shutting down won’t result in a potential
deadlock.

Currently, during shutdown the outgoingQueue channel is attempted to be
cleared by he writeHandler, however adding an additional select
statement serves as a mother layer of defense from nasty dead locks.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-19 17:00:18 -08:00
parent 12538ea922
commit 326c62c6b5
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -607,7 +607,11 @@ out:
// queueMsg queues a new lnwire.Message to be eventually sent out on the
// wire.
func (p *peer) queueMsg(msg lnwire.Message, doneChan chan struct{}) {
p.outgoingQueue <- outgoinMsg{msg, doneChan}
select {
case p.outgoingQueue <- outgoinMsg{msg, doneChan}:
case <-p.quit:
return
}
}
// ChannelSnapshots returns a slice of channel snapshots detailing all