Repository navigation
fix(ext/node): defer uv_write callbacks to prevent re-entrancy panic - #32919
Merged
Merged
Conversation
…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>
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
uv_writein the uv compat layer was firing write callbacks synchronously whentry_writesucceeded fully or failed. This caused aRefCelldouble-borrow panic ("RefCell already borrowed") when the caller (e.g.StreamWrap.write_buffer) held anOpStateborrow during theuv_writecall, and the synchronous callback re-entered JS which called another op borrowingOpState.uv_writeimplementations to always queue completed writes with a pre-determined status, deferring callbacks topoll_tcp_handle/poll_tty_handlein the event loop. This matches real libuv behavior whereuv_writenever fires callbacks synchronously.statusfield toWritePendingto support pre-completed entries that skip I/O in the drain loop.Closes #32891
Test plan
uv_write_callback_is_deferredverifying callback does not fire synchronously fromuv_write🤖 Generated with Claude Code