Repository navigation
win: fix error translation in uv_pipe, pipe write_cb, realpath/readlink, filemap, tty - #11
Conversation
Self-reviewProbed the diff across edge cases, blast radius, wrong-layer, and coverage. 34 concerns raised, 31 refuted. Three survived; the first two are fixed in fd3a06e. Fixed in fd3a06e
Remaining (noted, not fixed)Coverage gap. No new tests. Of the twelve error branches changed, one is exercised by the existing suite (
The remaining branches ( Happy to add the three cheap tests if wanted. Effect on BunTraced each changed function to its call sites in Bun. Bun's libuv return-code wrapper treats
Net for Bun: one intended user-visible change (pipe |
fd3a06e to
efe1c66
Compare
Points at the PR head (reachable via refs/pull/11/head on oven-sh/libuv so github-archive works). Swap to the squash-merge SHA once #11 lands; the tree is identical.
The existing child_process EPIPE test uses fs.closeSync(0) in the child, which is a no-op for fd<=2 in libuv's fs__close on Windows (fs.c:690), so the pipe never breaks and the test hangs. Restore its skipIf(isWindows). Instead add a Bun.spawn test where the child reads one byte then exits, leaving the parent's 256KB write to fail on the broken pipe. On Windows before oven-sh/libuv#11 this surfaces as code "EOF" (uv__process_pipe_write_req used the read-side translator); after the fix it is "EPIPE", matching Node and Unix.
…nk, filemap, tty
Subset of a broader src/win/ error-propagation audit; this commit keeps
only the fixes reachable from Bun's own code paths. All are also present
in upstream libuv/libuv v1.x.
pipe.c:
uv_pipe: translate the positive GetLastError() from
uv__create_pipe_pair() before returning from this public API; compare
errno against EMFILE (24), not UV_EMFILE (-4066).
uv__process_pipe_write_req: use uv_translate_write_sys_error() so
ERROR_BROKEN_PIPE / ERROR_NO_DATA surface as UV_EPIPE in write_cb,
matching the synchronous uv_write() path (stream.c) and Unix.
fs.c:
fs__filemap_ex_filter: the underlying NTSTATUS for
EXCEPTION_IN_PAGE_ERROR is ExceptionInformation[2], not [3]; index 3
is unpopulated so the code always fell through to UV_UNKNOWN.
fs__readlink_handle, fs__realpath_handle: when uv_utf16_to_wtf8 fails
with UV_ENOMEM, set ERROR_OUTOFMEMORY via SetLastError and return -1
so the caller's GetLastError() read is correct. fs__realpath previously
only checked == -1 and so reported success with req->ptr == NULL.
tty.c:
uv__tty_move_caret: return -1 after GetConsoleScreenBufferInfo failure
instead of reading an uninitialized CONSOLE_SCREEN_BUFFER_INFO and
potentially spinning on retry.
efe1c66 to
76367c0
Compare
oven-sh/libuv#11 was scoped down to the fixes reachable from Bun's own code; poll.c is no longer touched so the two win-poll patches apply unchanged.
Now on the bun branch, so the provenance comment is accurate again.
…35209) Companion to oven-sh/libuv#11 (merged as `2881ce5` on the `bun` branch). ## What changes for Bun oven-sh/libuv#11 fixes seven Windows error-translation/propagation bugs found by audit, scoped to those reachable from Bun's own code. Full breakdown is in [this comment on the libuv PR](oven-sh/libuv#11 (comment)). The one user-visible change: on Windows, an async write to a pipe whose read end has closed now delivers `{code: "EPIPE"}` to the write callback instead of `{code: "EOF"}`. Before the fix, `uv__process_pipe_write_req` used the read-side translator, which maps `ERROR_BROKEN_PIPE` / `ERROR_NO_DATA` to `UV_EOF` / `UV_EAGAIN`; the write-side translator maps both to `UV_EPIPE`, matching Node and the synchronous `uv_write()` path. This also fixes `shell::IOWriter::on_error`'s broken-pipe detection (`src/runtime/shell/IOWriter.rs:867`), which keys on `E::PIPE` and so was not firing when the failure arrived via the async write completion. ## Changes - `scripts/build/deps/libuv.ts`: bump `LIBUV_COMMIT` to `2881ce5` (the #11 merge) and add #11 to the provenance comment. - `test/js/bun/spawn/spawn.test.ts`: new test `stdin.end() rejects with EPIPE when the child exits before consuming the write`. The child reads one byte and exits, leaving 16MB queued on the parent's stdin (large enough to exceed macOS socket autotuning and the 64KB Windows named-pipe buffer), so `end()` is still draining when the read end closes. Verified fail-before on Windows (`caught.code === "EOF"` with the current release) and pass on Linux/macOS. The existing `child_process` `stdin write failure (EPIPE)` test is left skipped on Windows: its child does `fs.closeSync(0)`, but libuv's `fs__close` on Windows is a no-op for fd ≤ 2 (`src/win/fs.c:690`), so the pipe never breaks and the test hangs. That skip is unrelated to #11. ## Not changed (reachable from Bun, strict improvement, no code change needed) - `uv_pipe()` (used by `spawn/process.rs:2000`, `sys/lib.rs:4393`, `install/security_scanner.rs:1129`): previously returned a raw positive Win32 error on failure; Bun's `ReturnCode` predicate is `< 0`, so that leaked through as success with garbage fds. Now returns a negative `UV_E*`. Bun-side check was already correct. - `uv_fs_realpath` / `uv_fs_readlink` (used by `fs.realpath*`, `fs.readlink*`, `fs.cp`, `fs.watch`): OOM during UTF-16 conversion now reports `ENOMEM` instead of success-with-null or a stale error. - `fs__filemap_ex_filter` (`UV_FS_O_FILEMAP`, exposed via `fs.constants`): in-page errors now surface the real disk error instead of `UNKNOWN`. - `uv__tty_move_caret` (legacy console ANSI emulation): missing `return -1` added; bypassed on Windows 10+ where Bun enables VT mode at startup. <!-- robobun:evidence:begin --> --- **no test proof** · iteration 3 · Platform-specific test-only change; deferring to CI. <!-- robobun:evidence:end --> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…#35209) Companion to oven-sh/libuv#11 (merged as `2881ce5` on the `bun` branch). ## What changes for Bun oven-sh/libuv#11 fixes seven Windows error-translation/propagation bugs found by audit, scoped to those reachable from Bun's own code. Full breakdown is in [this comment on the libuv PR](oven-sh/libuv#11 (comment)). The one user-visible change: on Windows, an async write to a pipe whose read end has closed now delivers `{code: "EPIPE"}` to the write callback instead of `{code: "EOF"}`. Before the fix, `uv__process_pipe_write_req` used the read-side translator, which maps `ERROR_BROKEN_PIPE` / `ERROR_NO_DATA` to `UV_EOF` / `UV_EAGAIN`; the write-side translator maps both to `UV_EPIPE`, matching Node and the synchronous `uv_write()` path. This also fixes `shell::IOWriter::on_error`'s broken-pipe detection (`src/runtime/shell/IOWriter.rs:867`), which keys on `E::PIPE` and so was not firing when the failure arrived via the async write completion. ## Changes - `scripts/build/deps/libuv.ts`: bump `LIBUV_COMMIT` to `2881ce5` (the #11 merge) and add #11 to the provenance comment. - `test/js/bun/spawn/spawn.test.ts`: new test `stdin.end() rejects with EPIPE when the child exits before consuming the write`. The child reads one byte and exits, leaving 16MB queued on the parent's stdin (large enough to exceed macOS socket autotuning and the 64KB Windows named-pipe buffer), so `end()` is still draining when the read end closes. Verified fail-before on Windows (`caught.code === "EOF"` with the current release) and pass on Linux/macOS. The existing `child_process` `stdin write failure (EPIPE)` test is left skipped on Windows: its child does `fs.closeSync(0)`, but libuv's `fs__close` on Windows is a no-op for fd ≤ 2 (`src/win/fs.c:690`), so the pipe never breaks and the test hangs. That skip is unrelated to #11. ## Not changed (reachable from Bun, strict improvement, no code change needed) - `uv_pipe()` (used by `spawn/process.rs:2000`, `sys/lib.rs:4393`, `install/security_scanner.rs:1129`): previously returned a raw positive Win32 error on failure; Bun's `ReturnCode` predicate is `< 0`, so that leaked through as success with garbage fds. Now returns a negative `UV_E*`. Bun-side check was already correct. - `uv_fs_realpath` / `uv_fs_readlink` (used by `fs.realpath*`, `fs.readlink*`, `fs.cp`, `fs.watch`): OOM during UTF-16 conversion now reports `ENOMEM` instead of success-with-null or a stale error. - `fs__filemap_ex_filter` (`UV_FS_O_FILEMAP`, exposed via `fs.constants`): in-page errors now surface the real disk error instead of `UNKNOWN`. - `uv__tty_move_caret` (legacy console ANSI emulation): missing `return -1` added; bypassed on Windows 10+ where Bun enables VT mode at startup. <!-- robobun:evidence:begin --> --- **no test proof** · iteration 3 · Platform-specific test-only change; deferring to CI. <!-- robobun:evidence:end --> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Subset of a
src/win/*.cerror-translation/propagation audit, keeping only the fixes that are reachable from Bun's own code. All are also present in upstreamlibuv/libuvv1.x. Theuv__set_pipe_handleNtQueryInformationFilecase was already fixed in #10.uv_pipeGetLastError()value from a public negative-errno API;errno == UV_EMFILE(never true: +24 vs -4066)uv_translate_sys_error(err);errno == EMFILEuv__process_pipe_write_requv_translate_sys_error, soERROR_BROKEN_PIPEbecomesUV_EOFinwrite_cbuv_translate_write_sys_error, matching the syncuv_write()pathfs__realpath_handleUV_ENOMEMbut caller tests== -1, so OOM reports success withreq->ptr == NULLERROR_OUTOFMEMORYand returns -1fs__readlink_handleUV_ENOMEMwithout touching last-error; caller reads staleGetLastError()ERROR_OUTOFMEMORYand returns -1fs__filemap_ex_filterExceptionInformation[3]; NTSTATUS forEXCEPTION_IN_PAGE_ERRORis at[2][2]uv__tty_move_caretreturn -1afterGetConsoleScreenBufferInfofailure; reads uninitinfo, may spin onretryreturn -1Not included (found in the audit, but unreachable from Bun's own code)
uv_pipe_chmod(GetLastError()afterGet/SetSecurityInfo/SetEntriesInAcl),uv__slow_poll_thread_proc(SET_REQ_ERRORon hardcodedpoll_req_1),fs__sendfile(SET_REQ_RESULT(req, -1)),uv_pipe_connect(UV_E*→ NTSTATUS round-trip),fs__readdir(staleGetLastError()afteruv__convert_utf16_to_utf8). These are upstreamable separately.Verification
Built on Windows (mingw,
-DLIBUV_BUILD_TESTS=ON), no new warnings. Relevant libuv tests pass (fs_realpath,fs_readlink,pipe_connect_bad_name,pipe_connect_to_file,pipe_getsockname,pipe_overlong_path,pipe_set_chmod,ipc_listen_after_write,ipc_listen_before_write,tty,tty_cursor_move_absolute).