Skip to content

Windows: close a FileSink's file before end() and Bun.write(path, stream) report it closed - #46344

Draft
robobun wants to merge 2 commits into
mainfrom
robobun/24a1db87/windows-filesink-close-before-report
Draft

robobun wants to merge 2 commits into
mainfrom
robobun/24a1db87/windows-filesink-close-before-report

Conversation

@robobun

@robobun robobun commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

  • On Windows, await Bun.file(path).writer().end() and await Bun.write(path, new Response(stream)) settle with the file handle still open. This is read from the source. Nobody ran it on Windows before this pull request.
  • BaseWindowsPipeWriter::close_impl (src/io/PipeWriter.rs:1257) queues uv_fs_close on libuv's thread pool and calls on_close in the same frame.
  • With a write in flight, FileSink::on_write (src/runtime/webcore/FileSink.rs:428) settles the promise of end() before it queues the close.

Status: draft, tests first

  • This push has only tests. Both Windows lanes must record the failure on main before the fix is pushed.
  • test/js/bun/util/filesink.test.ts has new Windows-only rows. Each row opens the file with a share mode of 0 where the API reports done.
  • test/js/bun/util/filesink-close-time-probe.test.ts is temporary. It fails on purpose to print close times from the Windows lanes. It is removed before this pull request leaves draft.
  • Nothing in this pull request ran on a Windows machine outside CI.

Background

Rows for writer.end(), writer.close() and Bun.write(path, stream). Each
row opens the file with a share mode of 0 where the API reports done, and
counts the rounds in which another handle is still open. Windows only.
Each measurement fails on purpose so that its numbers reach the CI
output. This file is removed before the pull request leaves draft.
@robobun

robobun commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 1:10 PM PT - Oct 21st, 2026

❌ @robobun, your commit 83a69de has 2 failures in Build #130150 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 46344

That installs a local version of the PR into your bun-46344 executable, so you can run:

bun-46344 --bun

@robobun

robobun commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

Status

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant