@@ -801,12 +801,6 @@ fn BaseWindowsPipeWriter(
801
801
this .updateRef (event_loop , false );
802
802
}
803
803
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
-
810
804
fn onPipeClose (handle : * uv.Pipe ) callconv (.C ) void {
811
805
const this = bun .cast (* uv .Pipe , handle .data );
812
806
bun .default_allocator .destroy (this );
@@ -822,12 +816,13 @@ fn BaseWindowsPipeWriter(
822
816
if (this .source ) | source | {
823
817
switch (source ) {
824
818
.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
827
820
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 ;
831
826
}
832
827
},
833
828
.pipe = > | pipe | {
@@ -1021,9 +1016,8 @@ pub fn WindowsBufferedWriter(Parent: type, function_table: anytype) type {
1021
1016
// ALWAYS complete first
1022
1017
file .complete (was_canceled );
1023
1018
1024
- // If detached, file should be closing itself now
1019
+ // If detached, file may be closing (owned fd) or just stopped (non-owned fd)
1025
1020
if (parent_ptr == null ) {
1026
- bun .assert (file .state == .closing );
1027
1021
return ;
1028
1022
}
1029
1023
@@ -1348,9 +1342,8 @@ pub fn WindowsStreamingWriter(comptime Parent: type, function_table: anytype) ty
1348
1342
// ALWAYS complete first
1349
1343
file .complete (was_canceled );
1350
1344
1351
- // If detached, file should be closing itself now
1345
+ // If detached, file may be closing (owned fd) or just stopped (non-owned fd)
1352
1346
if (parent_ptr == null ) {
1353
- bun .assert (file .state == .closing );
1354
1347
return ;
1355
1348
}
1356
1349
0 commit comments