fix(test): run Node-API finalizers at test worker shutdown#35695
Merged
Conversation
The `deno run` and `deno bench` paths drain the NAPI finalizer queue via `MainWorker::run_napi_ref_finalizers()` at shutdown, but the `deno test` path did not, so finalizers registered with `napi_wrap`/`napi_add_finalizer` never fired for wrapped values held alive until the test run ended. Call `run_napi_ref_finalizers()` after the unload event in the test path, matching the run/bench paths and Node.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Native addons register finalizers via
napi_wrap/napi_add_finalizerthat are meant to run at environment teardown, even when the wrapped value
was never garbage collected during the run. This is how Node behaves: at
process exit
napi_env__::DeleteMe()callsRefTracker::FinalizeAll()overevery remaining reference, unconditionally, without forcing a GC between or
after test cases.
Deno already has the equivalent drain,
MainWorker::run_napi_ref_finalizers(),and calls it on the
deno runanddeno benchpaths. Thedeno testpathtore down the worker without calling it, so any addon that relied on a
shutdown finalizer (for example cleanup like WAL checkpointing) never ran it
when its code was wrapped in a test. This calls the drain after the unload
event in the test path so it matches the run/bench paths and Node.
Adds a regression test that wraps an object inside a
Deno.test, keeps itreachable so GC never collects it, and asserts the finalizer still runs at
test worker shutdown. It mirrors the existing
deno runvariant.Fixes #35692