signal: handle shutdown properly

This addresses issues related to the mobile lnd builds, where
calling `stopDaemon` and subsequently calling LndMobile's `Start`
results in crash.
This commit is contained in:
Hampus Sjöberg committed 2021-03-18 12:54:25 +01:00
1 parent 6046c5cf86
commit ada1bc701c
11 files changed
+170 -129

No files matched your search

+7 -3
View File
@@ -520,6 +520,9 @@ type rpcServer struct {
// extRestRegistrar is optional and specifies the registration
// callback to register external REST subservers.
extRestRegistrar RestRegistrar
// interceptor is used to be able to request a shutdown
interceptor signal.Interceptor
}
// A compile time check to ensure that rpcServer fully implements the
@@ -531,7 +534,8 @@ var _ lnrpc.LightningServer = (*rpcServer)(nil)
// be used to register the LightningService with the gRPC server.
func newRPCServer(cfg *Config, interceptorChain *rpcperms.InterceptorChain,
extSubserverCfg *RPCSubserverConfig,
extRestRegistrar RestRegistrar) *rpcServer {
extRestRegistrar RestRegistrar,
interceptor signal.Interceptor) *rpcServer {
// We go trhough the list of registered sub-servers, and create a gRPC
// handler for each. These are used to register with the gRPC server
@@ -552,6 +556,7 @@ func newRPCServer(cfg *Config, interceptorChain *rpcperms.InterceptorChain,
extSubserverCfg: extSubserverCfg,
extRestRegistrar: extRestRegistrar,
quit: make(chan struct{}, 1),
interceptor: interceptor,
}
}
@@ -5383,8 +5388,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
// a graceful shutdown of the daemon.
func (r *rpcServer) StopDaemon(ctx context.Context,
_ *lnrpc.StopRequest) (*lnrpc.StopResponse, error) {
signal.RequestShutdown()
r.interceptor.RequestShutdown()
return &lnrpc.StopResponse{}, nil
}