Skip to content

[Core] Fix Python 3.14 async-actor memory leak by re-anchoring stack protection to tracked fiber stacks - #65119

Open
rueian wants to merge 6 commits into
ray-project:masterfrom
rueian:fix-python-314-gc-fiber
Open

rueian wants to merge 6 commits into
ray-project:masterfrom
rueian:fix-python-314-gc-fiber

Conversation

@rueian

@rueian rueian commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Following the idea of #64772, but instead of using precomputed 32k/96k magic numbers, this PR keeps track of each fiber stack space and re-anchors stack protection accordingly.

Related issues

#63290

@rueian rueian added core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests labels Jul 30, 2026
…protection to tracked fiber stacks

Signed-off-by: Rueian Huang <[email protected]>
rueian added 2 commits July 30, 2026 09:40
Signed-off-by: Rueian Huang <[email protected]>
Signed-off-by: Rueian Huang <[email protected]>
@rueian
rueian marked this pull request as ready for review July 31, 2026 02:12
@rueian
rueian requested review from a team as code owners July 31, 2026 02:12
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces fiber stack protection for CPython 3.14+ to prevent memory leaks in async actors running on Boost fibers. It tracks fiber stack allocations via a new FiberStackRegistry and TrackingFiberStackAllocator, and updates CPython's stack protection bounds using ReanchorStackProtectionToCurrentFiberStack at task entry and resumption points. The reviewer provided valuable feedback, identifying additional yielding points in _raylet.pyx (such as generator slot reservation and object consumption) that also need stack re-anchoring upon resumption, and suggesting a defensive GIL-check assertion to prevent unsafe usage of the re-anchoring function.

Comment thread python/ray/_raylet.pyx Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 2d32247. Configure here.

Comment thread python/ray/_raylet.pyx Resolved
rueian added 3 commits July 30, 2026 21:49
Signed-off-by: Rueian Huang <[email protected]>
Keep the tracked-fiber stack protection implementation and drop the
heuristic 32 KiB / 96 KiB used-stack estimates merged via ray-project#64772.
Retain master's asyncio finalizer regression test and missing-API warning.

Signed-off-by: Rueian Huang <[email protected]>
Signed-off-by: Rueian Huang <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 18, 2026
@rueian

rueian commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

not stale

@rueian rueian added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Aug 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant