fix(ext/napi): keep event loop alive while uv_async_t handle is active#32702
Merged
bartlomieju merged 2 commits intodenoland:mainfrom Mar 14, 2026
Merged
fix(ext/napi): keep event loop alive while uv_async_t handle is active#32702bartlomieju merged 2 commits intodenoland:mainfrom
bartlomieju merged 2 commits intodenoland:mainfrom
Conversation
In libuv, `uv_async_init` starts the handle immediately and keeps the event loop running until `uv_close` is called. Our polyfill was missing this behavior — `uv_async_send` would spawn work to the main thread but nothing kept the event loop alive, so callbacks could be silently dropped. This adds `ref_op()` in `uv_async_init` and `unref_op()` in `uv_close` to match real libuv semantics. Also fixes `libuv_sys_lite::setup()` to run on all platforms in the test NAPI module (was Windows-only), and adds a `test-napi` subcommand to the `./x` developer CLI. Closes denoland#32614 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bartlomieju
commented
Mar 14, 2026
| napi_sys::setup(); | ||
| libuv_sys_lite::setup(); | ||
| } | ||
| unsafe { |
Member
Author
There was a problem hiding this comment.
Without this change the newly added tests were causing a panic.
bartlomieju
commented
Mar 14, 2026
Member
Author
There was a problem hiding this comment.
Drive-by cleanup to avoid deprecation warnings
bartlomieju
commented
Mar 14, 2026
bartlomieju
commented
Mar 14, 2026
Member
Author
There was a problem hiding this comment.
Drive by helper because it always takes me 5m to figure out correct invocation and agents are no better
littledivy
approved these changes
Mar 14, 2026
Member
littledivy
left a comment
There was a problem hiding this comment.
Reviewed the changes. No issues found.
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.
Summary
ref_op()inuv_async_initandunref_op()inuv_closeto match libuv semantics where an activeuv_async_thandle keeps the event loop alive until closedlibuv_sys_lite::setup()to run on all platforms in the test NAPI module (was gated behind#[cfg(windows)])test-napisubcommand to the./xdeveloper CLIuv_async_initkeeps the event loop alive without needing a threadsafe function workaroundCloses #32614
Test plan
"napi uv async keeps event loop alive"passes with fixmain(process exits before callback fires)./x test-napi— 58 passed, 0 failed)🤖 Generated with Claude Code