X Tutup
Skip to content

Wait for overlapped WriteFile completion in Rust#7383

Merged
youknowone merged 1 commit intoRustPython:mainfrom
youknowone:overlapped
Mar 8, 2026
Merged

Wait for overlapped WriteFile completion in Rust#7383
youknowone merged 1 commit intoRustPython:mainfrom
youknowone:overlapped

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Mar 8, 2026

On Windows, SimpleQueue skips write locking because pipe writes are assumed atomic. Without GIL, PipeConnection. _send_bytes races on _send_ov when multiple threads call send_bytes concurrently (e.g. _terminate_pool vs workers).

Wait for pending overlapped writes inside WriteFile before returning to Python, so ERROR_IO_PENDING is never exposed and the _send_ov assignment window is negligible.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced asynchronous file write operation handling on Windows to properly wait for completion of pending operations before returning, improving reliability.

On Windows, SimpleQueue skips write locking because pipe
writes are assumed atomic. Without GIL, PipeConnection.
_send_bytes races on _send_ov when multiple threads call
send_bytes concurrently (e.g. _terminate_pool vs workers).

Wait for pending overlapped writes inside WriteFile before
returning to Python, so ERROR_IO_PENDING is never exposed
and the _send_ov assignment window is negligible.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 5284d969-879f-4212-8073-f585bb3151d6

📥 Commits

Reviewing files that changed from the base of the PR and between fbab8fc and 233b798.

📒 Files selected for processing (1)
  • crates/vm/src/stdlib/_winapi.rs

📝 Walkthrough

Walkthrough

The overlapped WriteFile implementation now waits for pending I/O operations to complete instead of immediately returning an error code. When ERROR_IO_PENDING is encountered, the code invokes WaitForSingleObject to block until the overlapped event completes, then returns the overlapped object paired with a 0 status code.

Changes

Cohort / File(s) Summary
Overlapped WriteFile I/O Handling
crates/vm/src/stdlib/_winapi.rs
Modified the ERROR_IO_PENDING path to add synchronous waiting via WaitForSingleObject instead of returning the error immediately, returning (Overlapped, 0) upon completion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A pending write now waits so true,
No hasty errors slipping through,
WaitForSingleObject holds the line,
Overlapped events align, align! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone marked this pull request as ready for review March 8, 2026 09:03
@youknowone youknowone merged commit 0046c62 into RustPython:main Mar 8, 2026
11 of 13 checks passed
@youknowone youknowone deleted the overlapped branch March 8, 2026 09:04
youknowone added a commit to youknowone/RustPython that referenced this pull request Mar 8, 2026
On Windows, SimpleQueue skips write locking because pipe
writes are assumed atomic. Without GIL, PipeConnection.
_send_bytes races on _send_ov when multiple threads call
send_bytes concurrently (e.g. _terminate_pool vs workers).

Wait for pending overlapped writes inside WriteFile before
returning to Python, so ERROR_IO_PENDING is never exposed
and the _send_ov assignment window is negligible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup