From 849a215249238a2a217cb1e345562c47bf8a4525 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 16 Dec 2021 01:48:58 +0000 Subject: [PATCH] Add waiting for ctx.Done() when sending StepRunner stop result Signed-off-by: Ilya --- pkg/runner/step_runner.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/runner/step_runner.go b/pkg/runner/step_runner.go index 25d78830..ea8f9bf8 100644 --- a/pkg/runner/step_runner.go +++ b/pkg/runner/step_runner.go @@ -86,7 +86,7 @@ func (sr *StepRunner) Run( sr.mu.Unlock() // if an error occurred we already sent notification - sr.notifyStopped(nil) + sr.notifyStopped(ctx, nil) close(sr.resultsChan) ctx.Debugf("StepRunner finished") } @@ -274,13 +274,16 @@ func (sr *StepRunner) setErrLocked(ctx xcontext.Context, err error) { // notifyStopped is a blocking operation: should release the lock sr.mu.Unlock() - sr.notifyStopped(err) + sr.notifyStopped(ctx, err) sr.mu.Lock() } -func (sr *StepRunner) notifyStopped(err error) { +func (sr *StepRunner) notifyStopped(ctx xcontext.Context, err error) { sr.notifyStoppedOnce.Do(func() { - sr.resultsChan <- StepRunnerEvent{Err: err} + select { + case sr.resultsChan <- StepRunnerEvent{Err: err}: + case <-ctx.Done(): + } }) }