From 24f2b64c6ce427e133ad54a45c78b8b4f049c830 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Sun, 3 May 2020 13:58:54 -0700 Subject: [PATCH] Make sure to invoke CancelFunc in all cases --- processor.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/processor.go b/processor.go index adc7921..f0bd799 100644 --- a/processor.go +++ b/processor.go @@ -188,15 +188,17 @@ func (p *processor) exec() { <-p.sema /* release token */ }() - resCh := make(chan error, 1) - task := NewTask(msg.Type, msg.Payload) ctx, cancel := createContext(msg) p.cancelations.Add(msg.ID.String(), cancel) - go func() { - resCh <- perform(ctx, task, p.handler) + defer func() { + cancel() p.cancelations.Delete(msg.ID.String()) }() + resCh := make(chan error, 1) + task := NewTask(msg.Type, msg.Payload) + go func() { resCh <- perform(ctx, task, p.handler) }() + select { case <-p.quit: // time is up, quit this worker goroutine.