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.
This commit is contained in:
Slyghtning 2026-02-19 09:48:23 +01:00
parent d2d8e71ea0
commit eaf7883bcf
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF

View file

@ -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,