Skip to content

defer cancel() leaks memory #748

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

Merged

Conversation

JacobSMoller
Copy link
Contributor

Changes

Immediately call cancel() after we are done using the context. The for loop doesn't return until we succeed or parentCtx is cancelled if this takes a long time defer will never be called and this leaks memory.

In combination with the overflow here #747 this leaks memory quite fast when the retry loops starts running every 0s because of the overflow.

Verification

Ran a small piece of code calling an unavailable service and pprofed it.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Thanks for this, lets just update the comment

Co-authored-by: Johan Brandhorst-Satzkorn <[email protected]>
@johanbrandhorst johanbrandhorst merged commit c1423fc into grpc-ecosystem:main Feb 11, 2025
0 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants