Skip to content

fix(ext/napi): export uv_ref and uv_unref symbols#32562

Draft
bartlomieju wants to merge 2 commits intodenoland:mainfrom
bartlomieju:fix/napi-export-uv-ref-unref
Draft

fix(ext/napi): export uv_ref and uv_unref symbols#32562
bartlomieju wants to merge 2 commits intodenoland:mainfrom
bartlomieju:fix/napi-export-uv-ref-unref

Conversation

@bartlomieju
Copy link
Member

Summary

  • Adds no-op uv_ref and uv_unref stubs to ext/napi/uv.rs
  • Exports them in the symbol lists for all platforms

Native addons (e.g. zeromq) that call uv_ref/uv_unref crash with a null
pointer dereference because these symbols are resolved via dlsym at runtime
and Deno didn't export them.

Reproduction

import zmq from "zeromq";
const sock = new zmq.Pair();
await sock.bind('tcp://127.0.0.1:3000');

Crashes with EXC_BAD_ACCESS (code=1, address=0x0) — the call chain is:

napi_register_module_v1
  → zmq::Module::Module
    → zmq::Trash<...>::Trash
      → uv_unref(handle)  // resolved to NULL → crash

Status

This fixes the immediate uv_unref crash, but zeromq also needs additional uv
functions to fully work: uv_poll_init_socket, uv_poll_start, uv_poll_stop,
uv_timer_init, uv_timer_start, uv_timer_stop, uv_idle_init,
uv_idle_start, uv_check_init, uv_check_start, uv_os_getpid,
uv_queue_work.

There is a more complete uv compat layer in libs/core/uv_compat.rs (with
timers, idle/check/prepare handles, etc.) gated behind the uv_compat_export
feature flag. Integrating that with the NAPI layer's existing uv polyfill in
ext/napi/uv.rs would be the path to full zeromq support.

Ref #18345

Test plan

  • cargo check -p deno_napi passes
  • Confirmed zeromq gets past the uv_unref crash (now fails later on
    missing uv_poll_init_socket)

🤖 Generated with Claude Code

bartlomieju and others added 2 commits March 7, 2026 18:42
Native addons that call `uv_ref`/`uv_unref` (e.g. zeromq) crash with a
null pointer dereference because Deno didn't export these symbols. The
addon resolves them via `dlsym` at runtime, gets NULL, and segfaults
when calling.

Add no-op stubs for `uv_ref` and `uv_unref` and export them in the
symbol lists. These are no-ops because Deno's NAPI uv polyfill doesn't
track handle ref counts.

Note: zeromq also needs additional uv functions (uv_poll_*, uv_timer_*,
uv_idle_*, etc.) to fully work. There is a more complete uv compat layer
in libs/core/uv_compat.rs that could potentially be integrated.

Ref denoland#18345

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju changed the title WIP: fix(napi): export uv_ref and uv_unref symbols fix(ext/napi): export uv_ref and uv_unref symbols Mar 12, 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.

1 participant