From 5f2c394ba7bd3b5344cd6af2f1e6faa459ba16b6 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 13 Nov 2023 14:14:54 +0000 Subject: [PATCH] peer: panic early on queued nil messages --- peer/peer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/peer/peer.go b/peer/peer.go index e88f6f428e..c74b002926 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -1688,6 +1688,14 @@ cleanup: // // This function is safe for concurrent access. func (p *Peer) QueueMessage(msg wire.Message, doneChan chan<- struct{}) { + // Panic early on nil messages. This provides a more useful stack + // trace to callers than hitting the panic in a long-lived peer + // goroutine that contains no information about what caller queued the + // nil message. + if msg == nil { + panic("peer: nil message") + } + // Avoid risk of deadlock if goroutine already exited. The goroutine // we will be sending to hangs around until it knows for a fact that // it is marked as disconnected and *then* it drains the channels.