Skip to content

fix(addon): addObservableCleanupHook registers a distinct pair per call - #123

Merged
codetalcott merged 1 commit into
mainfrom
claude/stoic-volta-z29i0t
Sep 26, 2026
Merged

codetalcott merged 1 commit into
mainfrom
claude/stoic-volta-z29i0t

Conversation

@codetalcott

Copy link
Copy Markdown
Owner

Problem

addObservableCleanupHook() (a test export) registered (observable_cleanup_hook, NULL) on every call. A second call in one environment therefore handed Node's cleanup queue a duplicate pair. Node refuses that with a CHECK in CleanupQueue::Add that aborts the process, and Deno panics on it too.

I found this while auditing the cleanup-hook call sites after the function-pointer fix in codetalcott/napi-mojo#122. It is a separate bug: the pair really is duplicated, rather than two pointers failing to match. The rest of the audit found nothing: napi_remove_env_cleanup_hook is the only N-API call that matches a removal by function pointer, and the only other add/remove pair (removeCleanupHook) uses a single local pointer for both calls.

Change

  • Each call registers its own heap byte as arg. The hook frees it when it runs, which happens once, at teardown.
  • If the registration fails, the byte is freed before check_status raises.
  • tests/cleanup_hook_observed.test.js gains a test that registers twice and asserts exit 0, empty stderr, and two markers after the program's own output.

Testing

  • The new test failed with SIGABRT (Node's duplicate-pair assertion) before the fix, and passes after it.
  • Full suite: 849 passed, 12 skipped, 0 failed.
  • Double registration checked by hand under Bun 1.3.11 and Deno 2.9.6: both hooks run, exit 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_013tXV7MkRfP97g5hPfNNXHC


Generated by Claude Code

Every call registered (observable_cleanup_hook, NULL), so a second call
in one environment handed Node's cleanup queue a duplicate pair, which
it refuses with a CHECK that aborts the process (Deno panics on it too).
Found auditing the cleanup-hook sites after #122's function-pointer fix;
this one is a duplicate pair, not a pointer mismatch.

Each call now registers its own heap byte as `arg`, freed by the hook,
which runs once at teardown. tests/cleanup_hook_observed.test.js gains a
test that registers twice and asserts exit 0 and two markers after the
program's output; it failed with SIGABRT before the fix. Checked by hand
under Bun 1.3.11 and Deno 2.9.6 as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013tXV7MkRfP97g5hPfNNXHC
@codetalcott
codetalcott marked this pull request as ready for review September 26, 2026 18:39
@codetalcott
codetalcott merged commit 154afac into main Sep 26, 2026
11 checks passed
@codetalcott codetalcott mentioned this pull request Sep 26, 2026
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