Skip to content

Don't free Ractors in GC shutdown #14243

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
merged 1 commit into from
Aug 15, 2025

Conversation

jhawthorn
Copy link
Member

rb_gc_shutdown_call_finalizer_p returns false for threads and fibers, so it should probably do the same for all Ractors (not just the main one).

This hopefully mitigates a bug where, at exit, rb_ractor_terminate_all gets all Ractors to stop before continuing with the shutdown process. However when vm->ractor.cnt reaches 1, the native threads may still be running code at the end co_start, which reads/locks on th->ractor->threads.sched, so the Ractor is not safe to free.

A better solution might be to ensure that all native threads end up stopped or otherwise parked before this part of the shutdown, however that would be a bit more involved.

cc @peterzhu2118 @luke-gruber @etiennebarrie
cc @ko1

rb_gc_shutdown_call_finalizer_p returns false for threads and fibers, so
it should probably do the same for all Ractors (not just the main one).

This hopefully mitigates a bug where, at exit, rb_ractor_terminate_all
gets all Ractors to stop before continuing with the shutdown process.
However when vm->ractor.cnt reaches 1, the native threads may still be
running code at the end co_start, which reads/locks on
th->ractor->threads.sched, so the Ractor is not safe to free.

A better solution might be to ensure that all native threads end up
stopped or otherwise parked before this part of the shutdown, however
that would be a bit more involved.
@jhawthorn jhawthorn enabled auto-merge (rebase) August 15, 2025 18:38
Copy link

Tests Failed

✖️no tests failed ✔️62272 tests passed(1 flake)

@jhawthorn jhawthorn merged commit 149add8 into ruby:master Aug 15, 2025
89 of 91 checks passed
@jhawthorn jhawthorn deleted the ractors_dont_finalize_on_exit branch August 15, 2025 21:17
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