Skip to content

fix(tasklet): release the PyGreenlet_Switch return reference#38

Open
Rakdos8 wants to merge 1 commit into
carbonengine:mainfrom
Rakdos8:fix/greenlet-switch-ref-leak
Open

fix(tasklet): release the PyGreenlet_Switch return reference#38
Rakdos8 wants to merge 1 commit into
carbonengine:mainfrom
Rakdos8:fix/greenlet-switch-ref-leak

Conversation

@Rakdos8
Copy link
Copy Markdown

@Rakdos8 Rakdos8 commented May 15, 2026

Summary

Fixes a reference leak on the hottest scheduler path.

Problem

PyGreenlet_Switch returns a new reference to the switched-in value, but
it 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_XDECREF it. No semantic change — the code only ever used the
boolean 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.

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.
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.

1 participant