Skip to content

Commit 77661e3

Browse files
committed
Fix
1 parent 90e0d97 commit 77661e3

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/io/PipeWriter.zig

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,6 @@ fn BaseWindowsPipeWriter(
801801
this.updateRef(event_loop, false);
802802
}
803803

804-
fn onFileClose(handle: *uv.fs_t) callconv(.C) void {
805-
const file = bun.cast(*Source.File, handle.data);
806-
handle.deinit();
807-
bun.default_allocator.destroy(file);
808-
}
809-
810804
fn onPipeClose(handle: *uv.Pipe) callconv(.C) void {
811805
const this = bun.cast(*uv.Pipe, handle.data);
812806
bun.default_allocator.destroy(this);
@@ -822,12 +816,13 @@ fn BaseWindowsPipeWriter(
822816
if (this.source) |source| {
823817
switch (source) {
824818
.sync_file, .file => |file| {
825-
// Use state machine to safely cancel if operation in progress
826-
file.stop();
819+
// Use state machine to handle close after operation completes
827820
if (this.owns_fd) {
828-
// Use close_fs because fs might still be in use
829-
file.close_fs.data = file;
830-
_ = uv.uv_fs_close(uv.Loop.get(), &file.close_fs, file.file, onFileClose);
821+
file.detach();
822+
} else {
823+
// Don't own fd, just stop operations and detach parent
824+
file.stop();
825+
file.fs.data = null;
831826
}
832827
},
833828
.pipe => |pipe| {
@@ -1021,9 +1016,8 @@ pub fn WindowsBufferedWriter(Parent: type, function_table: anytype) type {
10211016
// ALWAYS complete first
10221017
file.complete(was_canceled);
10231018

1024-
// If detached, file should be closing itself now
1019+
// If detached, file may be closing (owned fd) or just stopped (non-owned fd)
10251020
if (parent_ptr == null) {
1026-
bun.assert(file.state == .closing);
10271021
return;
10281022
}
10291023

@@ -1348,9 +1342,8 @@ pub fn WindowsStreamingWriter(comptime Parent: type, function_table: anytype) ty
13481342
// ALWAYS complete first
13491343
file.complete(was_canceled);
13501344

1351-
// If detached, file should be closing itself now
1345+
// If detached, file may be closing (owned fd) or just stopped (non-owned fd)
13521346
if (parent_ptr == null) {
1353-
bun.assert(file.state == .closing);
13541347
return;
13551348
}
13561349

src/io/source.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ pub const Source = union(enum) {
5353
/// When true, file will close itself when the current operation completes.
5454
close_after_operation: bool = false,
5555

56-
/// Separate fs_t for close operations when needed by legacy code.
57-
/// Modern code should use the state machine and not need this.
58-
close_fs: uv.fs_t = std.mem.zeroes(uv.fs_t),
59-
6056
/// Get the File struct from an fs_t pointer using field offset.
6157
pub fn fromFS(fs: *uv.fs_t) *File {
6258
return @fieldParentPtr("fs", fs);

0 commit comments

Comments
 (0)