Skip to content

Avoid deadlocks during Windows overlapped cleanup - #9452

Merged
youknowone merged 2 commits into
RustPython:mainfrom
1ndahous3:asyncio_overlapped_cleanup
Oct 29, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
1ndahous3:asyncio_overlapped_cleanup

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Found while running an IPython cell with await: the cell completed, but the process hung during shutdown.

Summary

  • Release the Overlapped mutex before formatting or reporting a pending-operation error, avoiding recursive locking and allowing the unraisable hook to re-enter Python safely.
  • Detach the VM while cancelling and waiting for pending I/O. Report deallocation errors without exposing the dying object to the hook.

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup of asynchronous operations, including handling cancellation errors and closing associated resources before reporting failures.
    • Fixed a case where a Python process could fail to exit after running an event loop that was left open.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T06:36:57.321458Z d3b25a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b85582d and d3b25a9.

Files selected for processing: 2
  • crates/stdlib/src/overlapped.rs
  • extra_tests/snippets/stdlib_asyncio.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Overlapped cleanup now releases locks around cancellation and error reporting. It closes the event handle before reporting unrecognized cancellation errors. A subprocess test checks exit with an unclosed asyncio event loop.

Changes: Overlapped cleanup

Layer / File(s) Summary
Cancellation cleanup and process-exit coverage
crates/stdlib/src/overlapped.rs, extra_tests/snippets/stdlib_asyncio.py
Overlapped::del releases the VM thread lock during cancellation, closes the event handle before reporting unrecognized cancellation errors, and releases the inner mutex before formatting and reporting the error. The asyncio test checks that a subprocess exits successfully within 10 seconds when its event loop remains open.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: Minimal · up to d3b25

The cleanup change removes the identified shutdown deadlock mechanisms and adds a bounded process-exit regression test. No actionable merge-blocking issue was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing deadlocks during Windows overlapped cleanup.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing 1ndahous3:asyncio_overlapped_cleanup (d3b25a9) with main (b85582d)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone merged commit eaa36d6 into RustPython:main Oct 29, 2026
29 checks passed
@1ndahous3
1ndahous3 deleted the asyncio_overlapped_cleanup branch October 29, 2026 09:50
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.

2 participants