From c5837506ea8f6d202489f7e3af5a418e13cc0359 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 11 Aug 2026 11:56:04 -0500 Subject: [PATCH] test: avoid chain notifier mock deadlock Release the mock LND lock before sending the initial block height. A concurrent height notification can fill the buffered channel. Holding the lock while sending would then block invoice lookups and make the static loop-in test time out. --- test/chainnotifier_mock.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/chainnotifier_mock.go b/test/chainnotifier_mock.go index 9b4623bd..1da5f87d 100644 --- a/test/chainnotifier_mock.go +++ b/test/chainnotifier_mock.go @@ -129,13 +129,18 @@ func (c *mockChainNotifier) RegisterBlockEpochNtfn(ctx context.Context) ( } }() - // Send initial block height + // Snapshot the initial block height while holding the lock, but + // release it before sending. The buffered channel may already contain + // a concurrent height notification, and blocking on a full channel + // while holding the lock would deadlock other mock LND calls. c.lnd.lock.Lock() + currentHeight := c.lnd.Height + c.lnd.lock.Unlock() + select { - case blockEpochChan <- c.lnd.Height: + case blockEpochChan <- currentHeight: case <-ctx.Done(): } - c.lnd.lock.Unlock() <-ctx.Done() })