refactor(core): libuv compatibility improvements for uv_compat#33015
Merged
bartlomieju merged 8 commits intodenoland:mainfrom Mar 27, 2026
Merged
refactor(core): libuv compatibility improvements for uv_compat#33015bartlomieju merged 8 commits intodenoland:mainfrom
bartlomieju merged 8 commits intodenoland:mainfrom
Conversation
Improve the uv_compat layer to more closely match libuv's behavior: - Cached loop time: update once per tick instead of reading wall clock - Socket lifecycle: uv_tcp_bind creates real socket immediately, preserving fd identity across bind/listen/connect - Deferred errors: EADDRINUSE from bind is reported from listen/connect - Validation: reject operations on closing handles, duplicate reads/shutdowns return UV_EALREADY - Write improvements: simplified uv_write with try-write-immediate, two-phase callback firing in poll loop, 32-per-tick starvation limits - Read improvements: 32-per-tick limits, UV_ENOBUFS on null alloc, real error codes instead of UV_EOF, early exit on partial reads - Handle cleanup: fire UV_ECANCELED for pending writes/shutdowns on close, flush write queue on connect failure - Connection detection: MSG_PEEK probe during writes to detect broken connections promptly - TTY: don't close stdio fds, proper error codes in poll loop Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover deferred EADDRINUSE, UV_EALREADY guards, closing-handle rejection, ephemeral port resolution before listen, and UV_ECANCELED on close with pending writes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The import was unix-only but the function is now also used in the Windows code path for real error code reporting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On Windows, SO_REUSEADDR allows multiple sockets to bind to the same port (unlike Unix where it only allows TIME_WAIT reuse). Match libuv by setting SO_EXCLUSIVEADDRUSE on Windows instead, which prevents port sharing and ensures EADDRINUSE is properly reported. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Factors out standalone libuv compliance improvements from #32819 (TLS rewrite) so they can land and be tested independently.
update_time()once per tick instead of wall clock readsuv_tcp_bindcreates real socket immediately, preserving fd identity across bind/listen/connect; deferredEADDRINUSEreportingUV_EALREADYfor duplicate reads/shutdownsuv_writewith try-write-immediate + deferred callbacks, two-phase callback firing, 32-per-tick starvation limitsUV_ENOBUFSon null alloc, real error codes instead ofUV_EOF, early exit on partial readsUV_ECANCELEDfor pending writes/shutdowns on close, write queue flush on connect failureWhat stays in #32819:
uv_tcp_close_reset()+set_so_linger_reset()(TLS-specific RST close API).Test plan
cargo check -p deno_core— compilescargo check -p deno_runtime— downstream compilescargo test -p deno_core— all tests pass🤖 Generated with Claude Code