mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
multi: Allow interrupt of server startup.
This commit does two things. It starts up the server in a way that it can be interrupted and shutdown gracefully. Moreover it makes sure that subsystems clean themselves up when they fail to start. This makes sure that depending subsytems can shutdown gracefully as well and the shutdown process is not stuck.
This commit is contained in:
28
lnd.go
28
lnd.go
@@ -674,11 +674,33 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
|
||||
bestHeight)
|
||||
|
||||
// With all the relevant chains initialized, we can finally start the
|
||||
// server itself.
|
||||
if err := server.Start(); err != nil {
|
||||
// server itself. We start the server in an asynchronous goroutine so
|
||||
// that we are able to interrupt and shutdown the daemon gracefully in
|
||||
// case the startup of the subservers do not behave as expected.
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
errChan <- server.Start()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
err := server.Stop()
|
||||
if err != nil {
|
||||
ltndLog.Warnf("Stopping the server including all "+
|
||||
"its subsystems failed with %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-errChan:
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return mkErr("unable to start server: %v", err)
|
||||
|
||||
case <-interceptor.ShutdownChannel():
|
||||
return nil
|
||||
}
|
||||
defer server.Stop()
|
||||
|
||||
// We transition the server state to Active, as the server is up.
|
||||
interceptorChain.SetServerActive()
|
||||
|
Reference in New Issue
Block a user