Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logic to wait for executor stop #392

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ const (
type executor struct {
jobFunctions chan jobFunction
stopCh chan struct{}
stoppedCh chan struct{}
limitMode limitMode
maxRunningJobs *semaphore.Weighted
}

func newExecutor() executor {
return executor{
jobFunctions: make(chan jobFunction, 1),
stopCh: make(chan struct{}, 1),
stopCh: make(chan struct{}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need capacity for this channel. Closing the channel is enough to tell the stop.

stoppedCh: make(chan struct{}),
}
}

Expand Down Expand Up @@ -113,13 +115,13 @@ func (e *executor) start() {
case <-e.stopCh:
cancel()
runningJobsWg.Wait()
e.stopCh <- struct{}{}
close(e.stoppedCh)
return
}
}
}

func (e *executor) stop() {
e.stopCh <- struct{}{}
<-e.stopCh
close(e.stopCh)
<-e.stoppedCh
Comment on lines -123 to +126
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need two channels for this use case. In the previous implementation, struct{}{} sent at L123 might be received at L124, which means start() loop never stops.

}