Skip to content

Commit

Permalink
Add waiting for ctx.Done() when sending StepRunner stop result
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya <[email protected]>
  • Loading branch information
rihter007 committed Dec 16, 2021
1 parent 0f755b4 commit 849a215
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/runner/step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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():
}
})
}

Expand Down

0 comments on commit 849a215

Please sign in to comment.