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
2020-08-28 11:18:15 +02:00
parent 6046c5cf86
commit ada1bc701c
11 changed files with 170 additions and 129 deletions

View File

@@ -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