Skip to content

refactor(core): libuv compatibility improvements for uv_compat#33015

Merged
bartlomieju merged 8 commits intodenoland:mainfrom
bartlomieju:refactor/uv-compat-improvements
Mar 27, 2026
Merged

refactor(core): libuv compatibility improvements for uv_compat#33015
bartlomieju merged 8 commits intodenoland:mainfrom
bartlomieju:refactor/uv-compat-improvements

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

Factors out standalone libuv compliance improvements from #32819 (TLS rewrite) so they can land and be tested independently.

  • Cached loop time: update_time() once per tick instead of wall clock reads
  • Socket lifecycle: uv_tcp_bind creates real socket immediately, preserving fd identity across bind/listen/connect; deferred EADDRINUSE reporting
  • Validation guards: reject ops on closing handles, UV_EALREADY for duplicate reads/shutdowns
  • Write path: simplified uv_write with try-write-immediate + deferred callbacks, two-phase callback firing, 32-per-tick starvation limits
  • Read path: 32-per-tick limits, UV_ENOBUFS on null alloc, real error codes instead of UV_EOF, early exit on partial reads
  • Handle cleanup: UV_ECANCELED for pending writes/shutdowns on close, write queue flush on connect failure
  • Connection liveness: MSG_PEEK probe during writes to detect broken connections
  • TTY: don't close stdio fds, proper error codes

What stays in #32819: uv_tcp_close_reset() + set_so_linger_reset() (TLS-specific RST close API).

Test plan

  • cargo check -p deno_core — compiles
  • cargo check -p deno_runtime — downstream compiles
  • cargo test -p deno_core — all tests pass

🤖 Generated with Claude Code

bartlomieju and others added 3 commits March 26, 2026 20:52
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>
@bartlomieju bartlomieju marked this pull request as ready for review March 26, 2026 20:26
bartlomieju and others added 5 commits March 26, 2026 21:28
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>
Copy link
Copy Markdown
Member

@littledivy littledivy left a comment

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 47b20af into denoland:main Mar 27, 2026
112 checks passed
@bartlomieju bartlomieju deleted the refactor/uv-compat-improvements branch March 27, 2026 07:14
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.

2 participants