fix(tasklet): release the PyGreenlet_Switch return reference#38
Open
Rakdos8 wants to merge 1 commit into
Open
Conversation
PyGreenlet_Switch returns a new reference to the switched-in value, but it was assigned straight into a bool, so the object was never released. This leaks a reference on every tasklet switch (the hottest path on the server) and grows unbounded over uptime. Capture the result, derive the success bool from it, and Py_XDECREF it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a reference leak on the hottest scheduler path.
Problem
PyGreenlet_Switchreturns a new reference to the switched-in value, butit was assigned straight into a
bool. The object was never released,leaking a reference on every tasklet switch and growing memory unbounded
over server uptime.
Fix
Capture the result into a
PyObject*, derive the success bool from it,and
Py_XDECREFit. No semantic change — the code only ever used theboolean meaning of the result.
Type
Performance / stability — memory leak on the critical path (Critical;
whole-shard blast radius).
Testing
Manual review; control flow (
if(!ret),return ret) preserved.