Skip to content

Commit

Permalink
end recovery on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Aug 7, 2024
1 parent db3a4a2 commit e4217f0
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ func (w *Wallet) quitChan() <-chan struct{} {

// Stop signals all wallet goroutines to shutdown.
func (w *Wallet) Stop() {
w.endRecoveryAndWait()

w.quitMu.Lock()
quit := w.quit
w.quitMu.Unlock()
Expand Down Expand Up @@ -1380,6 +1382,22 @@ type (
heldUnlock chan struct{}
)

// endRecoveryAndWait tells (*Wallet).recovery to stop, if running, and waits
// for it to exit.
func (w *Wallet) endRecoveryAndWait() {
if recoverySyncI := w.recovering.Load(); recoverySyncI != nil {
recoverySync := recoverySyncI.(*recoverySyncer)
// If recovery is still running, it will end early with an error
// once we set the quit flag.
atomic.StoreUint32(&recoverySync.quit, 1)

select {
case <-recoverySync.done:
case <-w.quitChan():
}
}
}

// walletLocker manages the locked/unlocked state of a wallet.
func (w *Wallet) walletLocker() {
var timeout <-chan time.Time
Expand Down Expand Up @@ -1472,19 +1490,7 @@ out:

// We can't lock the manager if recovery is active because we use
// cryptoKeyPriv and cryptoKeyScript in recovery.
if recoverySyncI := w.recovering.Load(); recoverySyncI != nil {
recoverySync := recoverySyncI.(*recoverySyncer)
// If recovery is still running, it will end early with an error
// once we set the quit flag.
atomic.StoreUint32(&recoverySync.quit, 1)

select {
case <-recoverySync.done:
case <-quit:
break out
}

}
w.endRecoveryAndWait()

timeout = nil
err := w.Manager.Lock()
Expand Down

0 comments on commit e4217f0

Please sign in to comment.