mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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.
This commit is contained in:
parent
aa79fa5262
commit
c5837506ea
1 changed files with 8 additions and 3 deletions
|
|
@ -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()
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue