From 1c1140f4f327dfed482abcdceb0ed3cdb6c2fb7b Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 10 Jan 2016 14:52:32 +0300 Subject: [PATCH] Fix a rare crash when restarting a system task after shutdown was called --- satan.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/satan.go b/satan.go index 50441c5..24b2c3c 100644 --- a/satan.go +++ b/satan.go @@ -143,6 +143,16 @@ func (s *Satan) processTask(t *task) { } func (s *Satan) processSystemTask(t *task) { + // Abort starting a system task if shutdown was already called. Otherwise + // incrementing a wait group counter will cause a panic. This should be an + // extremely rare scenario when a system task crashes and tries to restart + // after a shutdown call. + select { + case <-s.shutdownSystem: + return + default: + } + s.wgSystem.Add(1) defer s.wgSystem.Done() defer func() {