diff --git a/core/services/workflows/engine.go b/core/services/workflows/engine.go index 362fb7fb098..2692b53f5e8 100644 --- a/core/services/workflows/engine.go +++ b/core/services/workflows/engine.go @@ -355,9 +355,25 @@ func (e *Engine) registerTrigger(ctx context.Context, t *triggerCapability, trig }} } + e.wg.Add(1) go func() { - for event := range eventsCh { - e.triggerEvents <- event + defer e.wg.Done() + + for { + select { + case <-e.stopCh: + return + case event, isOpen := <-eventsCh: + if !isOpen { + return + } + + select { + case <-e.stopCh: + return + case e.triggerEvents <- event: + } + } } }()