From 326c62c6b5232854af04958d845268ed4a65d196 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 19 Dec 2016 17:00:18 -0800 Subject: [PATCH] peer: ensure queueMsg won't create deadlock if peer shutting down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- peer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/peer.go b/peer.go index d2c620c5..2bce0a9b 100644 --- a/peer.go +++ b/peer.go @@ -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