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

util+plugins: Fix potential memory leak with explicit timer cancellation. #7089

Conversation

philipaconrad
Copy link
Contributor

@philipaconrad philipaconrad commented Oct 2, 2024

What changed?

This commit adds a utility for explicitly creating cancelable timers, to avoid possible memory leaks caused by some time.After timers in select statements never being GC'd properly. This issue is fixed in Go 1.23, but since we're still on Go 1.21, this will resolve the possibility of leaks in the mean time.

The patch fixes every instance in OPA of <-time.After(...) that we have, so this should fix the issue until OPA eventually upgrades to Go 1.23 (which changes the behavior of time.After).

Note: One of these instances occurs in topdown/http.go, so after this fix is integrated into an OPA release, we may want to poke some OPA memory leak reporters again, especially if they were using http.send extensively in their policies.

Additional Resources

Copy link

netlify bot commented Oct 2, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 910f252
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/66fda1bbb657a5000853e5f0
😎 Deploy Preview https://deploy-preview-7089--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thank you!

This commit adds a utility for explicitly creating cancelable timers,
to avoid a possible memory leak caused by timer.After. This issue is
fixed in Go 1.23, but since we're still on Go 1.21, this will resolve
the possibility of leaks in the mean time.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
@philipaconrad philipaconrad force-pushed the philip/explicit-timer-cancel branch from d6f9ada to 910f252 Compare October 2, 2024 19:40
@philipaconrad
Copy link
Contributor Author

ℹ️ Rebasing the PR through the Github Web UI. Once it goes green, I'll squash and merge it.

@philipaconrad philipaconrad merged commit f32ad09 into open-policy-agent:main Oct 2, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants