Skip to content

Fix GC_test#test_enable leaving GC disabled for the rest of the suite - #3059

Merged
soutaro merged 1 commit into
ruby:masterfrom
ko1:fix-gc-test-enable-restore
Jul 31, 2026
Merged

Fix GC_test#test_enable leaving GC disabled for the rest of the suite#3059
soutaro merged 1 commit into
ruby:masterfrom
ko1:fix-gc-test-enable-restore

Conversation

@ko1

@ko1 ko1 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

GC.enable returns whether GC was disabled before the call (true when the call actually re-enabled GC), not whether it was enabled. The ensure clause GC.disable unless was_enabled therefore inverted the restore: in the common case where GC is enabled when the test starts, GC.enable returns false and the ensure clause disables GC permanently.

Every test that runs after GC_test then executes with GC turned off, so the whole stdlib test process accumulates garbage until exit. On the ruby/ruby Windows CI runners this reaches the process memory limit and the suite dies with NoMemoryError (deterministically), and on all platforms it silently changes what later tests exercise.

Rename the variable to what the value actually means and restore the previous state with GC.disable if was_disabled, mirroring test_disable.

`GC.enable` returns whether GC was *disabled* before the call (true when
the call actually re-enabled GC), not whether it was enabled. The ensure
clause `GC.disable unless was_enabled` therefore inverted the restore:
in the common case where GC is enabled when the test starts, GC.enable
returns false and the ensure clause disables GC permanently.

Every test that runs after GC_test then executes with GC turned off, so
the whole stdlib test process accumulates garbage until exit. On the
ruby/ruby Windows CI runners this reaches the process memory limit and
the suite dies with NoMemoryError (deterministically), and on all
platforms it silently changes what later tests exercise.

Rename the variable to what the value actually means and restore the
previous state with `GC.disable if was_disabled`, mirroring test_disable.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@soutaro
soutaro added this pull request to the merge queue Jul 31, 2026
Merged via the queue into ruby:master with commit 7534c7e Jul 31, 2026
24 checks passed
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