Skip to content

fix(gc tests): zero hand-built Map/Set fixture headers over recycled arena bytes (#11362) - #11363

Merged
proggeramlug merged 2 commits into
mainfrom
fix/11362-dirty-page-map-segv
Sep 26, 2026
Merged

proggeramlug merged 2 commits into
mainfrom
fix/11362-dirty-page-map-segv

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11362

Root cause

This was a test-fixture bug (class (b), cross-test residue). The collector is fine.

The crash report for the SIGSEGV shows the faulting frame. It is not in the dirty-page scan at all:

EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x7878787878787948
  drop_glue<perry_runtime::map::store::MapStore> + 20
  drop_glue<perry_runtime::arena::block::Arena> + 284
  thread_local ... lazy::destroy<HotCell<UnsafeCell<Arena>>>
  _pthread_tsd_cleanup / _pthread_exit

The test's own body passes. The crash happens afterwards, during libtest thread teardown. Arena::drop walks every GC_TYPE_MAP header (walk_block_maps) and calls drop_map_store_at_thread_exit, which does Box::from_raw(header.store).

The old-generation Map fixture alloc_old_test_map was duplicated in gc/tests/barrier.rs and gc/tests/helper_stores.rs. It got its header from arena_alloc_gc_old and wrote only size, used, capacity and entries. That allocator reuses swept same-size holes and bump space without zeroing. js_map_alloc says so explicitly and initialises every word. So the fixture's store (an owned Box) and meta (a traced edge) kept whatever the previous occupant left. Here that was 0x7878787878787878, an earlier test's "xxx…" string bytes. Whether the recycled bytes are non-zero depends on what ran earlier in the process, which is why the test passed in isolation (60/60) and failed only in the full suite.

The same crash, with the same fault address and stack, also hit a second user of the fixture, test_incremental_barrier_marks_external_map_and_set_slots.

Fix

  • Move the Map fixture into gc/tests/support.rs as alloc_old_test_map / init_test_map_header / retire_old_test_map. The header is zeroed with write_bytes before any field is set, so store and meta are always null.
  • The Set fixture alloc_old_test_set had the same defect: meta (a traced edge), used (the scanned extent) and compaction_epoch were left as residue. It now zeroes too.
  • Add a test-only accessor map::test_map_store_word so a test can read the private store word.

No collector code changes.

Regression test

gc::tests::barrier::old_test_map_fixture_initialises_every_header_word_over_recycled_bytes fills a fresh old-gen map header with 0x78, the way a previous occupant would, and then runs the fixture initialiser. It asserts that store, meta, size, used and compaction_epoch are all zero. It scrubs the header before asserting, so a failing arm fails as a normal test instead of as a thread-exit SIGSEGV.

  • With the old initialiser (field-by-field writes): FAILED ... MapHeader.store left: 8680820740569200760 (0x7878787878787878), right: 0, exit 101.
  • With the fix: ok, exit 0.

Validation

  • Full perry-runtime lib suite, release, RUST_TEST_THREADS=1: 5 of 5 serial runs clean (4611 passed, exit 0 each).
  • Loaded mass run, 7 concurrent workers × 30 full-suite runs per arm, same test binary shape: see the PR comment for the numbers.
  • cargo fmt --all -- --check: clean.
  • SKIP_COMPILE_GATES=1 ./scripts/run_lint_gates.sh: 1 of 92 failed. The failure is only "Public benchmark evidence freshness", which is already red on main.

Summary by CodeRabbit

  • Tests
    • Improved garbage-collection test fixtures to avoid intermittent crashes caused by stale fixture data.
    • Added regression coverage to verify that map and set fixtures start with clean metadata. These changes strengthen test reliability without changing end-user functionality.

Ralph Küpper added 2 commits September 26, 2026 05:04
…arena bytes

The old-generation Map fixture (duplicated in gc/tests/barrier.rs and
gc/tests/helper_stores.rs) wrote only size/used/capacity/entries on a
header from arena_alloc_gc_old, which reuses swept holes without zeroing.
MapHeader.store (an owned Box) and .meta (a traced edge) kept an earlier
test's bytes. At thread exit the arena drop walks every GC_TYPE_MAP header
and Box::from_raw's its store; with residue 0x7878787878787878 (an earlier
test's "xxx..." string) it faulted in drop_glue<MapStore> after the test
had already passed, killing the suite (#11362). Same crash seen under
test_incremental_barrier_marks_external_map_and_set_slots.

Move the fixture into gc/tests/support.rs, zero the whole header first
(as js_map_alloc initialises every word), and do the same for the Set
fixture, whose meta/used were also residue. Add a deterministic
regression test that poisons the header with 0x78 before initialising it.

Fixes #11362
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 19c3feb0-9de5-4f05-9f85-4d4132cafa78

📥 Commits

Reviewing files that changed from the base of the PR and between a15b224 and 82df822.

📒 Files selected for processing (6)
  • changelog.d/11363-gc-test-map-fixture-residue.md
  • crates/perry-runtime/src/gc/tests/barrier.rs
  • crates/perry-runtime/src/gc/tests/helper_stores.rs
  • crates/perry-runtime/src/gc/tests/support.rs
  • crates/perry-runtime/src/map.rs
  • crates/perry-runtime/src/map/store.rs
💤 Files with no reviewable changes (1)
  • crates/perry-runtime/src/gc/tests/helper_stores.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

GC test fixtures now clear header memory before initialization. A barrier regression test poisons a MapHeader, initializes it, and checks selected fields, including the raw store pointer.

Changes

GC map header tests

Layer / File(s) Summary
Initialize and retire GC test fixtures
crates/perry-runtime/src/gc/tests/support.rs, crates/perry-runtime/src/gc/tests/barrier.rs, crates/perry-runtime/src/gc/tests/helper_stores.rs, changelog.d/11363-gc-test-map-fixture-residue.md
Set fixtures now clear the full header payload. Shared Map fixture helpers clear the header before initialization and reset fields before freeing entries. The former local map helpers were removed. The changelog records the fixture issue and changes.
Check initialized map header fields
crates/perry-runtime/src/map/store.rs, crates/perry-runtime/src/map.rs, crates/perry-runtime/src/gc/tests/barrier.rs
A test-only accessor and re-export expose the raw store pointer as an integer. The regression test poisons a MapHeader, initializes it, and checks captured fields for zero values.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 82df8

The fixture change appears ready to merge after normal checks; no actionable risk remains in the supplied evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: zeroing hand-built GC test fixture headers to prevent recycled arena bytes from causing crashes.
Description check ✅ Passed The description provides a detailed root cause, fix, regression test, linked issue, validation results, and scope statement. It does not follow the template headings or include the checklist, but it c…
Linked Issues check ✅ Passed The changes address #11362. Shared Map and Set fixture helpers now zero complete headers before field initialization, including Map store and meta and Set meta and used. The regression test po…
Out of Scope Changes check ✅ Passed All changed files support #11362. The changes centralize GC test fixtures, add a test-only raw MapHeader.store accessor, update the Set fixture, and add regression coverage. No unrelated collector o…
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Loaded mass run: 7 concurrent workers × 30 full-suite runs per arm (RUST_TEST_THREADS=1, release lib test binary). The arms ran one after the other on the same host.

arm runs clean SIGSEGV in the map-fixture tests other failures
main (a15b224) 210 190 6: 5× test_incremental_barrier_marks_external_map_and_set_slots, 1× test_dirty_page_map_entry_scan_is_external_range_bounded. Every crash report is drop_glue<MapStore> ← Arena::drop at thread exit, fault address 0x7878787878787948 13× turnloop_net::…queued_writes_report_backpressure_and_drain_in_order (panic under load), 1× SIGABRT in turnloop_pool::…a_full_pool_queue_refuses…
this PR 210 201 0 8× the same turnloop_net load panic, 1× SIGSEGV in async_hooks::test_support::tests::native_async_resource_accepts_string_and_symbol_expandos (see below)

The one SIGSEGV left in the fix arm is a different defect. It happens mid-test, not at thread exit: get_accessor_descriptor ← exotic_set_property ← js_put_value_set dereferences 0x4010000000000010, which is the bit pattern of the double 4.0 used as a pointer. It has nothing to do with the Map/Set fixtures, and it should be tracked separately.

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.

GC test flake: gc::tests::barrier::test_dirty_page_map_entry_scan_is_external_range_bounded SIGSEGVs intermittently in the full perry-runtime suite

1 participant