fix unpaired deref when write_file fails due to nametoolong (#23438)

Fixes test\regression\issue\23316-long-path-spawn.test.ts

The problem was ``await Bun.write(join(deepPath, "test.js"),
`console.log("hello");`);`` was failing because the name was too long,
but it failed before refConcurrently was called and it called
unrefConcurrently after failing. so then when the subprocess spawned it
didn't ref.

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
pfg
2025-10-10 03:48:47 -07:00
committed by GitHub
parent 312a86fd43
commit c50db1dbfb
2 changed files with 5 additions and 6 deletions

View File

@@ -350,6 +350,7 @@ pub const WriteFileWindows = struct {
err: ?bun.sys.Error = null,
total_written: usize = 0,
event_loop: *jsc.EventLoop,
poll_ref: bun.Async.KeepAlive = .{},
owned_fd: bool = false,
@@ -404,7 +405,7 @@ pub const WriteFileWindows = struct {
},
}
write_file.event_loop.refConcurrently();
write_file.poll_ref.ref(write_file.event_loop.virtual_machine);
return write_file;
}
@@ -481,7 +482,6 @@ pub const WriteFileWindows = struct {
fn mkdirp(this: *WriteFileWindows) void {
log("mkdirp", .{});
this.mkdirp_if_not_exists = false;
this.event_loop.refConcurrently();
const path = this.file_blob.store.?.data.file.pathlike.path.slice();
jsc.Node.fs.Async.AsyncMkdirp.new(.{
@@ -494,8 +494,6 @@ pub const WriteFileWindows = struct {
}
fn onMkdirpComplete(this: *WriteFileWindows) void {
this.event_loop.unrefConcurrently();
const err = this.err;
this.err = null;
if (err) |err_| {
@@ -539,7 +537,6 @@ pub const WriteFileWindows = struct {
}
pub fn onFinish(container: *WriteFileWindows) WriteFileWindowsError {
container.event_loop.unrefConcurrently();
var event_loop = container.event_loop;
event_loop.enter();
defer event_loop.exit();
@@ -623,6 +620,7 @@ pub const WriteFileWindows = struct {
}
this.file_blob.store.?.deref();
this.bytes_blob.store.?.deref();
this.poll_ref.disable();
uv.uv_fs_req_cleanup(&this.io_request);
bun.destroy(this);
}

View File

@@ -89,7 +89,8 @@ test("spawn should handle cwd paths with disabled 8.3 names on Windows", async (
stdout: "inherit",
stderr: "inherit",
});
await proc.exited;
const exitCode = await proc.exited;
if (exitCode !== 0) throw new Error("process exited");
} catch (e) {
err = e;
}