Skip to content

Wait for a pending GC before re-disabling GC after GC.start - #134

Open
k0kubun wants to merge 1 commit into
ruby:mainfrom
k0kubun:redisable-gc-after-gc
Open

k0kubun wants to merge 1 commit into
ruby:mainfrom
k0kubun:redisable-gc-after-gc

Conversation

@k0kubun

@k0kubun k0kubun commented Oct 27, 2026

Copy link
Copy Markdown
Member

GC.start runs even while GC is disabled, so mmtk_handle_user_collection_request enables GC around the collection and disables it again afterward. While GC is enabled, another Ractor's GC.start can request a GC that hasn't run yet when this thread tries to re-disable GC. disable_collection fails in that state, and we panicked with "failed to re-disable GC after GC".

This showed up as an intermittent crash of test_ractor_nt_switch.rb's gc_finalize_deferred test on the MMTk CI (example). Instead of panicking, block for the pending GC and try again. Since a GC is already requested, the retry joins it instead of starting a new one.

GC.start runs even while GC is disabled, so mmtk_handle_user_collection_request
enables GC around the collection and disables it again afterward. While GC is
enabled, another Ractor's GC.start can request a GC that hasn't run yet when
this thread tries to re-disable GC. disable_collection fails in that state,
and we panicked with "failed to re-disable GC after GC".

This showed up as an intermittent crash of test_ractor_nt_switch.rb's
gc_finalize_deferred test on the MMTk CI. Instead of panicking, block for the
pending GC and try again. Since a GC is already requested, the retry joins it
instead of starting a new one.
@k0kubun
k0kubun marked this pull request as ready for review October 27, 2026 21:43
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