Merge pull request #8497 from ziggie1984/shutdown-bugfix

routing: shutdown chanrouter correctly.
This commit is contained in:
Olaoluwa Osuntokun
2024-08-01 16:48:50 -07:00
committed by GitHub
14 changed files with 230 additions and 83 deletions

28
lnd.go
View File

@@ -694,11 +694,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()