Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/vm/src/stdlib/_winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,26 @@ mod _winapi {

err
};

// Without GIL, the Python-level PipeConnection._send_bytes has a
// race on _send_ov when the caller (SimpleQueue) skips locking on
// Windows. Wait for completion here so the caller never sees
// ERROR_IO_PENDING and never blocks in WaitForMultipleObjects,
// keeping the _send_ov window negligibly small.
if err == ERROR_IO_PENDING {
let event = ov.inner.lock().overlapped.hEvent;
vm.allow_threads(|| unsafe {
windows_sys::Win32::System::Threading::WaitForSingleObject(
event,
windows_sys::Win32::System::Threading::INFINITE,
);
});
let result = vm
.ctx
.new_tuple(vec![ov.into_pyobject(vm), vm.ctx.new_int(0u32).into()]);
return Ok(result.into());
}

let result = vm
.ctx
.new_tuple(vec![ov.into_pyobject(vm), vm.ctx.new_int(err).into()]);
Expand Down
Loading