From c7096881717ecba8d86fc591c1cee0940e31ec2a Mon Sep 17 00:00:00 2001 From: Andy Lindeman Date: Fri, 8 May 2020 05:45:59 -0400 Subject: [PATCH] Deregister signal channel (#16) If `SignalHandler` is being used as a mechanism to exit the program entirely, these resources will be cleaned up naturally. But if not, the signal should be explicitly deregistered. Make sure the channel is eligible to be garbage collected and that no additional signals should be delivered to the channel after this actor exits. --- actors.go | 1 + 1 file changed, 1 insertion(+) diff --git a/actors.go b/actors.go index ef93495..d1bc754 100644 --- a/actors.go +++ b/actors.go @@ -15,6 +15,7 @@ func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() er return func() error { c := make(chan os.Signal, 1) signal.Notify(c, signals...) + defer signal.Stop(c) select { case sig := <-c: return SignalError{Signal: sig}