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: exit ticktock goroutine when pool is closed #264

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

GlebRadchenko
Copy link
Contributor

@GlebRadchenko GlebRadchenko commented Dec 18, 2022


name: Pull request
about: Fixes a bug
title: 'fix ticktock memory leaks'
labels: ''
assignees: ''

1. Are you opening this pull request for bug-fixs, optimizations or new feature?

bugfix

2. Please describe how these code changes achieve your intention.

The fix enables ticktock goroutine to stop it's execution.

3. Please link to the relevant issues (if any).

#263

4. Which documentation changes (if any) need to be made/updated because of this PR?

4. Checklist

  • I have squashed all insignificant commits.
  • I have commented my code for explaining package types, values, functions, and non-obvious lines.
  • I have written unit tests and verified that all tests passes (if needed).
  • I have documented feature info on the README (only when this PR is adding a new feature).
  • (optional) I am willing to help maintain this change if there are issues with it later.

@@ -116,10 +116,25 @@ func (p *Pool) ticktock() {
defer ticker.Stop()

for range ticker.C {
if p.IsClosed() {
Copy link
Owner

Choose a reason for hiding this comment

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

I think the better way to do this is to use context and select in for loop, like purgeStaleWorkers() does.
So you should pass the context to ticktock() and use an atomic int32 to indicate whether ticktock() is done, handle these properly in ReleaseTimeout() and Reboot().

In short, just do what exactly purgeStaleWorkers() has already done.

Copy link
Contributor Author

@GlebRadchenko GlebRadchenko Dec 19, 2022

Choose a reason for hiding this comment

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

Addressed, but I'm still concerned if atomic int32 is helpful for ticktock case since there is no worker-related awaiting logic. lmk if you need anything else

@panjf2000 panjf2000 added bug Something isn't working pending development Requested PR owner to improve code and waiting for the result labels Dec 18, 2022
@codecov
Copy link

codecov bot commented Dec 19, 2022

Codecov Report

Base: 92.88% // Head: 93.17% // Increases project coverage by +0.28% 🎉

Coverage data is based on head (42086fe) compared to base (3fbd956).
Patch coverage: 97.14% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
+ Coverage   92.88%   93.17%   +0.28%     
==========================================
  Files           9        9              
  Lines         759      791      +32     
==========================================
+ Hits          705      737      +32     
  Misses         41       41              
  Partials       13       13              
Flag Coverage Δ
unittests 93.17% <97.14%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pool.go 90.49% <97.14%> (+0.67%) ⬆️
pool_func.go 91.88% <97.14%> (+0.50%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner

@panjf2000 panjf2000 left a comment

Choose a reason for hiding this comment

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

LGTM

@panjf2000 panjf2000 added the pending merged This PR has been reviewed and approved label Dec 19, 2022
@panjf2000 panjf2000 merged commit 23c4f48 into panjf2000:master Dec 20, 2022
@GlebRadchenko GlebRadchenko deleted the bugfix-ticktok branch December 22, 2022 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending development Requested PR owner to improve code and waiting for the result pending merged This PR has been reviewed and approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants