From 95e0633b2ff46e6d60bb46127e5e73aa9bec41da Mon Sep 17 00:00:00 2001 From: Daniel Tomcej Date: Fri, 18 Jun 2021 09:43:10 -0700 Subject: [PATCH] Create buffered signals channel --- cmd/context.go | 20 -------------------- cmd/traefik/traefik.go | 4 +++- 2 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 cmd/context.go diff --git a/cmd/context.go b/cmd/context.go deleted file mode 100644 index 867cb3f72..000000000 --- a/cmd/context.go +++ /dev/null @@ -1,20 +0,0 @@ -package cmd - -import ( - "context" - "os" - "os/signal" - "syscall" -) - -// ContextWithSignal creates a context canceled when SIGINT or SIGTERM are notified. -func ContextWithSignal(ctx context.Context) context.Context { - newCtx, cancel := context.WithCancel(ctx) - signals := make(chan os.Signal) - signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) - go func() { - <-signals - cancel() - }() - return newCtx -} diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index 0a772de1e..887b00c95 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -6,9 +6,11 @@ import ( stdlog "log" "net/http" "os" + "os/signal" "path/filepath" "sort" "strings" + "syscall" "time" "github.com/coreos/go-systemd/daemon" @@ -119,7 +121,7 @@ func runCmd(staticConfiguration *static.Configuration) error { return err } - ctx := cmd.ContextWithSignal(context.Background()) + ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) if staticConfiguration.Experimental != nil && staticConfiguration.Experimental.DevPlugin != nil { var cancel context.CancelFunc