Skip to content

fix(ext/node): defer uv_write callbacks to prevent re-entrancy panic - #32919

Merged
bartlomieju merged 1 commit into
mainfrom
fix/uv-write-deferred-callbacks
Mar 23, 2026
Merged

bartlomieju merged 1 commit into
mainfrom
fix/uv-write-deferred-callbacks

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Summary

  • uv_write in the uv compat layer was firing write callbacks synchronously when try_write succeeded fully or failed. This caused a RefCell double-borrow panic ("RefCell already borrowed") when the caller (e.g. StreamWrap.write_buffer) held an OpState borrow during the uv_write call, and the synchronous callback re-entered JS which called another op borrowing OpState.
  • Changed both TCP and TTY uv_write implementations to always queue completed writes with a pre-determined status, deferring callbacks to poll_tcp_handle/poll_tty_handle in the event loop. This matches real libuv behavior where uv_write never fires callbacks synchronously.
  • Added a status field to WritePending to support pre-completed entries that skip I/O in the drain loop.

Closes #32891

Test plan

  • Added regression test uv_write_callback_is_deferred verifying callback does not fire synchronously from uv_write
  • All 58 uv_compat tests pass
  • Node.js unit tests pass (buffer, net, http, http2, tty)

🤖 Generated with Claude Code

…ntrancy panic

uv_write was firing write callbacks synchronously when try_write succeeded,
causing a RefCell double-borrow panic when callers (e.g. StreamWrap ops)
held an OpState borrow during the call. This matches real libuv behavior
where uv_write never fires callbacks synchronously.

Closes #32891

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@littledivy littledivy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju
bartlomieju merged commit dcc04bb into main Mar 23, 2026
112 checks passed
@bartlomieju
bartlomieju deleted the fix/uv-write-deferred-callbacks branch March 23, 2026 11:21
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.

Deno panicked after upgrade v2.7.7

2 participants