fix: fix the worker queue reboot but the slice is empty#360
fix: fix the worker queue reboot but the slice is empty#360panjf2000 merged 6 commits intopanjf2000:devfrom
Conversation
|
Good catch, thanks! But can we reuse the queue instead of reallocating it? |
|
I think we can just remove these lines: Lines 173 to 174 in 1bf9cfd |
Sure. It's a good idea. |
Maybe, but generally speaking, a PR shouldn't introduce irrelevant changes when trying to fix something. Let's do this in a separate PR and make sure the |
Agree. I have restored it. |
|
By the way, I have read some articles, and these show |
panjf2000
left a comment
There was a problem hiding this comment.
Rename these two tests to TestRebootNewPoolCalc and TestRebootNewPoolWithPreAllocCalc. Then move them to ants_test.go
|
Also, you need to fix the lint issues. |
Done! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #360 +/- ##
==========================================
- Coverage 94.11% 94.09% -0.02%
==========================================
Files 14 14
Lines 968 966 -2
==========================================
- Hits 911 909 -2
Misses 46 46
Partials 11 11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1. Are you opening this pull request for bug-fixs, optimizations or new feature?
Yes, for bug-fixs.
2. Please describe how these code changes achieve your intention.
Below is the analysis
1. Variable Initialize
The problem is that when we use preAlloc option, the workerQueue will initialize once.
Then, It will put the worker into the items slice as much as user defined.
The len is {size} and cap = {size} of
items []worker.2. Pool Release
However, when user call the Release() or ReleaseTimeout() function, it will trigger reset() function and make all workers in
itemsbe nil.The len is 0 and cap = {size} of
items []worker.3. Reboot and No Workers
When the user want to reuse the Pool and call
Reboot()function, the pool was restart but the len of workerQueue still 0.But
retrieveWorker()still can get the workers until it put back to workerQueue.Here is the point. When the new worker is prepared to put back to the workerQueue,
wq.itemslen is 0.If we direct access it, it will panic.
3. Please link to the relevant issues (if any).
Issue #358.
4. Which documentation changes (if any) need to be made/updated because of this PR?
No document description changed.
4. Checklist