lnd: add interrupt handler to handle shutdown requests while syncing
chain backend
This commit is contained in:
parent
5c42a88038
commit
4a200d28eb
19
lnd.go
19
lnd.go
@ -570,7 +570,20 @@ func lndMain() error {
|
|||||||
ltndLog.Infof("Waiting for chain backend to finish sync, "+
|
ltndLog.Infof("Waiting for chain backend to finish sync, "+
|
||||||
"start_height=%v", bestHeight)
|
"start_height=%v", bestHeight)
|
||||||
|
|
||||||
|
// We'll add an interrupt handler in order to process shutdown
|
||||||
|
// requests while the chain backend syncs.
|
||||||
|
addInterruptHandler(func() {
|
||||||
|
rpcServer.Stop()
|
||||||
|
fundingMgr.Stop()
|
||||||
|
})
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-shutdownChannel:
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
synced, _, err := activeChainControl.wallet.IsSynced()
|
synced, _, err := activeChainControl.wallet.IsSynced()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -617,16 +630,12 @@ func lndMain() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addInterruptHandler(func() {
|
addInterruptHandler(func() {
|
||||||
ltndLog.Infof("Gracefully shutting down the server...")
|
|
||||||
rpcServer.Stop()
|
rpcServer.Stop()
|
||||||
fundingMgr.Stop()
|
fundingMgr.Stop()
|
||||||
server.Stop()
|
|
||||||
|
|
||||||
if pilot != nil {
|
if pilot != nil {
|
||||||
pilot.Stop()
|
pilot.Stop()
|
||||||
}
|
}
|
||||||
|
server.Stop()
|
||||||
server.WaitForShutdown()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Wait for shutdown signal from either a graceful server stop or from
|
// Wait for shutdown signal from either a graceful server stop or from
|
||||||
|
@ -663,11 +663,6 @@ func (s *server) Stopped() bool {
|
|||||||
return atomic.LoadInt32(&s.shutdown) != 0
|
return atomic.LoadInt32(&s.shutdown) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForShutdown blocks until all goroutines have been stopped.
|
|
||||||
func (s *server) WaitForShutdown() {
|
|
||||||
s.wg.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
// initNetworkBootstrappers initializes a set of network peer bootstrappers
|
// initNetworkBootstrappers initializes a set of network peer bootstrappers
|
||||||
// based on the server, and currently active bootstrap mechanisms as defined
|
// based on the server, and currently active bootstrap mechanisms as defined
|
||||||
// within the current configuration.
|
// within the current configuration.
|
||||||
|
@ -48,10 +48,8 @@ func mainInterruptHandler() {
|
|||||||
isShutdown = true
|
isShutdown = true
|
||||||
ltndLog.Infof("Shutting down...")
|
ltndLog.Infof("Shutting down...")
|
||||||
|
|
||||||
// Run handlers in LIFO order.
|
// Execute the interrupt callbacks in FIFO order.
|
||||||
for i := range interruptCallbacks {
|
for _, callback := range interruptCallbacks {
|
||||||
idx := len(interruptCallbacks) - 1 - i
|
|
||||||
callback := interruptCallbacks[idx]
|
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user