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:
1 parent
6046c5cf86
commit
ada1bc701c
11 files changed
+170
-129
No files matched your search
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
||||
"github.com/lightningnetwork/lnd/signal"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -467,7 +466,7 @@ func openChannelPsbt(rpcCtx context.Context, ctx *cli.Context,
|
||||
// the server.
|
||||
go func() {
|
||||
select {
|
||||
case <-signal.ShutdownChannel():
|
||||
case <-rpcCtx.Done():
|
||||
fmt.Printf("\nInterrupt signal received.\n")
|
||||
close(quit)
|
||||
|
||||
|
||||
@@ -41,14 +41,15 @@ const (
|
||||
)
|
||||
|
||||
func getContext() context.Context {
|
||||
if err := signal.Intercept(); err != nil {
|
||||
shutdownInterceptor, err := signal.Intercept()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ctxc, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
<-signal.ShutdownChannel()
|
||||
<-shutdownInterceptor.ShutdownChannel()
|
||||
cancel()
|
||||
}()
|
||||
return ctxc
|
||||
|
||||
+10
-9
@@ -10,9 +10,16 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Hook interceptor for os signals.
|
||||
shutdownInterceptor, err := signal.Intercept()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Load the configuration, and parse any command line options. This
|
||||
// function will also set up logging properly.
|
||||
loadedConfig, err := lnd.LoadConfig()
|
||||
loadedConfig, err := lnd.LoadConfig(shutdownInterceptor)
|
||||
if err != nil {
|
||||
if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
|
||||
// Print error if not due to help request.
|
||||
@@ -24,16 +31,10 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Hook interceptor for os signals.
|
||||
if err := signal.Intercept(); err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Call the "real" main in a nested manner so the defers will properly
|
||||
// be executed in the case of a graceful shutdown.
|
||||
if err := lnd.Main(
|
||||
loadedConfig, lnd.ListenerCfg{}, signal.ShutdownChannel(),
|
||||
if err = lnd.Main(
|
||||
loadedConfig, lnd.ListenerCfg{}, shutdownInterceptor,
|
||||
); err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in new issue
Block a user