From eaf7883bcf7bf353d8adfe8ea89a38957e9b6d23 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Thu, 19 Feb 2026 09:48:23 +0100 Subject: [PATCH] openchannel: fix shimPending data race Protect the shimPending variable with a sync.Mutex since it is accessed from multiple goroutines: the main loop goroutine and the server error handling goroutine. Without synchronization this is a data race. --- staticaddr/openchannel/manager.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/staticaddr/openchannel/manager.go b/staticaddr/openchannel/manager.go index af2f5162..36ccdc75 100644 --- a/staticaddr/openchannel/manager.go +++ b/staticaddr/openchannel/manager.go @@ -430,6 +430,7 @@ func (m *Manager) openChannelPsbt(ctx context.Context, var ( pendingChanID [32]byte + shimMu sync.Mutex shimPending = true psbtFinalized bool basePsbtBytes []byte @@ -466,6 +467,9 @@ func (m *Manager) openChannelPsbt(ctx context.Context, // maybeCancelShim is a helper function that cancels the funding shim // with the RPC server in case we end up aborting early. maybeCancelShim := func() { + shimMu.Lock() + defer shimMu.Unlock() + // If the user canceled while there was still a shim registered // with the wallet, release the resources now. if shimPending { @@ -566,7 +570,9 @@ func (m *Manager) openChannelPsbt(ctx context.Context, err.Error(), cancelErr, ) { + shimMu.Lock() shimPending = false + shimMu.Unlock() } closeQuit() @@ -679,7 +685,9 @@ func (m *Manager) openChannelPsbt(ctx context.Context, // As soon as the channel is pending, there is no more // shim that needs to be canceled. If the user // interrupts now, we don't need to clean up anything. + shimMu.Lock() shimPending = false + shimMu.Unlock() hash, err := chainhash.NewHash( update.ChanPending.Txid,