mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Kill the server if original context is canceled
This commit is contained in:
@@ -41,13 +41,22 @@ func init() {
|
||||
}
|
||||
|
||||
func contextWithSignal(ctx context.Context, signals ...os.Signal) context.Context {
|
||||
ctx, halt := context.WithCancel(context.Background())
|
||||
newCTX, halt := context.WithCancel(ctx)
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, signals...)
|
||||
go func() {
|
||||
<-c
|
||||
logrus.Info("Halting...")
|
||||
halt()
|
||||
for {
|
||||
select {
|
||||
case <-c:
|
||||
logrus.Info("Halting...")
|
||||
halt()
|
||||
return
|
||||
case <-ctx.Done():
|
||||
logrus.Info("Halting... Original server context canceled.")
|
||||
halt()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return ctx
|
||||
return newCTX
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user