Skip to content

finalization_registry.ts: tolerate a target kept alive by the conservative stack scan - #112

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-finalization-registry-flake
Nov 20, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-finalization-registry-flake

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

The release run for v0.0-pre-alpha133 (https://github.com/ASDAlexander77/TypeScriptCompiler/actions/runs/44782299326/job/136474517636) failed on one test: finalization_registry.ts, ubuntu-26.04, -mm=gc, release/compile leg only (it passed in the jit, debug/compile and debug/jit legs of the same job):

Assertion `a callback for each freed target, once' failed.

The test dropped two targets and required both to be freed. Under gc the collector scans the stack conservatively, so a stray word can keep one alive. That makes it a flaky test, not a bug in the library.

Change (test only): 200 dropped targets (every other one registered with itself as the unregister token), at least 90% must get a callback. weakmap_weakset.ts already does it this way. These checks stay exact:

  • no callback runs during GC_gcollect itself, only at the registry's next use
  • each held value gets at most one callback
  • the next cleanupSome() runs nothing again
  • the held target gets no callback, and unregister still finds and then forgets its token

Local (Windows, -mm=gc): 10/10 JIT runs and 30/30 exe runs pass. A copy that demands more callbacks than there were targets fails, so the threshold check is live.

🤖 Generated with Claude Code

…ative stack scan

The test dropped two targets and required a callback for both after GC_gcollect. Under gc the
collector scans the stack conservatively, so a stray word can keep one alive: it failed once on
ubuntu-26.04 (release, compile) in the v0.0-pre-alpha133 release run and passed in the other three legs.

Now 200 dropped targets (half registered with themselves as the token) and at least 90% must get a
callback, as weakmap_weakset.ts does. What stays exact: no callback during the collection itself,
each held value at most once, nothing again on the next use, none for the held target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 23ebaad into main Nov 20, 2026
4 of 10 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.

1 participant