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 memleak in safe.Pool #6140
fix memleak in safe.Pool #6140
Conversation
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.
LGTM
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.
LGTM 👼
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.
Nice fix 👏
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.
In fact, I think that the routineCtx slice (or map) is not needed anymore because it was only used for Start
mechanism and this mechanism is not used anymore.
I think we should be able to remove all the routines
(without Ctx) too, by migrating every old behaviour calls, but this will be done in a future PR.
@mpl I kept the bot/no-merge
label for your review, you can merge it when you think it's OK for you.
LGTM |
safe.Pool is not a pool in the usual sense as it is not bounded and it keeps on appending new goroutines, instead of reusing a limited number of goroutines. Moreover, even when a goroutine is done, there's still a small footprint of it, as there is a reference to it that was appended in a slice, and that never gets removed. For this reason, it should not be used in places where potentially lots of go routines are generated, such as in the mirroring service, where there's one go routine per incoming request. Fixes traefik#6125
What does this PR do?
safe.Pool is not a pool in the usual sense as it is not bounded and
it keeps on appending new goroutines, instead of reusing a limited
number of goroutines. Moreover, even when a goroutine is done, there's
still a small footprint of it, as there is a reference to it that was
appended in a slice, and that never gets removed.
This PR fixes the pool by using maps instead of slices, and by making sure the entry in the map corresponding to a goroutine is removed from the map when the goroutine terminates.
Motivation
Fixes #6125
More
[ ] Added/updated tests[ ] Added/updated documentationAdditional Notes
Co-authored-by: Julien Salleyron julien.salleyron@gmail.com