mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
chainntnfs: handling for potential deadlocks during system shutdown
If the lnd daemon is shut down while multiple subsystems are attempting to register for notifications, the blocking of those chain notifier registrations may cause the daemon shutdown to deadlock. The additions in this commit allow the registration functions to return errors rather than potentially deadlock when the chain notifier is shut down.
This commit is contained in:
parent
b991cd3d78
commit
def39799c5
@ -2,6 +2,7 @@ package btcdnotify
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -546,7 +547,12 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint) (*chainntnfs.S
|
|||||||
spendChan: make(chan *chainntnfs.SpendDetail, 1),
|
spendChan: make(chan *chainntnfs.SpendDetail, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
b.notificationRegistry <- ntfn
|
select {
|
||||||
|
case <-b.quit:
|
||||||
|
return nil, errors.New("chainntnfs: system interrupt while " +
|
||||||
|
"attempting to register for spend notification.")
|
||||||
|
case b.notificationRegistry <- ntfn:
|
||||||
|
}
|
||||||
|
|
||||||
// The following conditional checks to ensure that when a spend notification
|
// The following conditional checks to ensure that when a spend notification
|
||||||
// is registered, the output hasn't already been spent. If the output
|
// is registered, the output hasn't already been spent. If the output
|
||||||
@ -603,12 +609,16 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *wire.ShaHash,
|
|||||||
negativeConf: make(chan int32, 1),
|
negativeConf: make(chan int32, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
b.notificationRegistry <- ntfn
|
select {
|
||||||
|
case <-b.quit:
|
||||||
|
return nil, errors.New("chainntnfs: system interrupt while " +
|
||||||
|
"attempting to register for confirmation notification.")
|
||||||
|
case b.notificationRegistry <- ntfn:
|
||||||
return &chainntnfs.ConfirmationEvent{
|
return &chainntnfs.ConfirmationEvent{
|
||||||
Confirmed: ntfn.finConf,
|
Confirmed: ntfn.finConf,
|
||||||
NegativeConf: ntfn.negativeConf,
|
NegativeConf: ntfn.negativeConf,
|
||||||
}, nil
|
}, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// blockEpochRegistration represents a client's intent to receive a
|
// blockEpochRegistration represents a client's intent to receive a
|
||||||
@ -625,9 +635,13 @@ func (b *BtcdNotifier) RegisterBlockEpochNtfn() (*chainntnfs.BlockEpochEvent, er
|
|||||||
epochChan: make(chan *chainntnfs.BlockEpoch, 20),
|
epochChan: make(chan *chainntnfs.BlockEpoch, 20),
|
||||||
}
|
}
|
||||||
|
|
||||||
b.notificationRegistry <- registration
|
select {
|
||||||
|
case <-b.quit:
|
||||||
|
return nil, errors.New("chainntnfs: system interrupt while " +
|
||||||
|
"attempting to register for block epoch notification.")
|
||||||
|
case b.notificationRegistry <- registration:
|
||||||
return &chainntnfs.BlockEpochEvent{
|
return &chainntnfs.BlockEpochEvent{
|
||||||
Epochs: registration.epochChan,
|
Epochs: registration.epochChan,
|
||||||
}, nil
|
}, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user