-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Clear pending tasks in the worker when the context is canceled to avoid deadlocks in StopAndWait when tasks are queued for the worker. #62
Conversation
…id deadlocks in StopAndWait when tasks are queued for the worker.
Hey @CorentinClabaut, thanks for submitting this PR 🙌 |
Hey @alitto no problem for the PR :) |
It seems a test is failing due to a race condition 🤔 . github.com/alitto/pond.(*WorkerPool).stop.func1()
/home/runner/work/pond/pond/pond.go:358 +0x44 I wonder if that's related to moving the closing of the |
I just saw this error as well === RUN TestSubmitWithContextCancelWithIdleTasks
pond_blackbox_test.go:582: Expected int32(1) but was int32(2)
--- FAIL: TestSubmitWithContextCancelWithIdleTasks (0.00s) This one seems to be due to select {
case <-context.Done():
...
case task, ok := <-tasks:
...
} Here if both channels contain something any of the case could be triggered (https://stackoverflow.com/questions/46200343/force-priority-of-go-select-statement) I can push a fix for this and see if it fixes the race condition as well. |
Hey @alitto it should be all good now. |
Hey @alitto The issue is now:
I'm not sure how this issue could be triggered by this PR though. Could it be that in some situations the purge might reset idleWorkerCount before we do the check in the test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving some comments, looks good overall 👍
Mhm, I think the // Submit a task to ensure at least 1 worker is started
pool.SubmitAndWait(func() {
atomic.AddInt32(&doneCount, 1)
})
// Ensure idle worker count is updated
time.Sleep(1 * time.Millisecond)
assertEqual(t, 1, pool.IdleWorkers()) |
That makes sense, I can see that it's what you have done in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much @CorentinClabaut! I will take care of fixing the codecov action which is missing a token apparently and then also publish a new version of pond with your changes 🙂
Thank you for the merge @alitto :) |
closes #61