mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'respect_original_cancel' into 'master'
Kill the server if original context is canceled See merge request !120
This commit is contained in:
@@ -41,13 +41,22 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func contextWithSignal(ctx context.Context, signals ...os.Signal) context.Context {
|
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)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, signals...)
|
signal.Notify(c, signals...)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
for {
|
||||||
|
select {
|
||||||
|
case <-c:
|
||||||
logrus.Info("Halting...")
|
logrus.Info("Halting...")
|
||||||
halt()
|
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