Skip to content

Commit

Permalink
Fix race condition
Browse files Browse the repository at this point in the history
This ensures that the waitgroup properly waits for all steps. There used to be a race condition that caused it to call Wait before Add()
  • Loading branch information
jaredoconnell committed Jul 10, 2024
1 parent 24ccfd5 commit 44b07de
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/step/plugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ func (r *runnableStep) Start(input map[string]any, runID string, stageChangeHand
runID: runID,
}

s.wg.Add(1) // Wait for the run to finish before closing.
go s.run()

return s, nil
Expand Down Expand Up @@ -922,8 +923,8 @@ func (r *runningStep) closeComponents(closeATP bool) error {
return nil
}

// Note: Caller must add 1 to the waitgroup before calling.
func (r *runningStep) run() {
r.wg.Add(1) // Wait for the run to finish before closing.
defer func() {
r.cancel() // Close before WaitGroup done
r.wg.Done() // Done. Close may now exit.
Expand Down

0 comments on commit 44b07de

Please sign in to comment.