Skip to content

Commit

Permalink
Merge pull request #57 from linuxboot/fix/wait_for_ctx_in_notify_stopped
Browse files Browse the repository at this point in the history
Add waiting for ctx.Done() when sending StepRunner stop result
  • Loading branch information
rihter007 authored Dec 16, 2021
2 parents 0f755b4 + 849a215 commit 2ac7f3a
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 2ac7f3a

Please sign in to comment.