Skip to content

Ensure close and connection_lost do not race in Win32#101

Merged
puddly merged 8 commits into
devfrom
puddly/windows-clean-close
Jun 9, 2026
Merged

Ensure close and connection_lost do not race in Win32#101
puddly merged 8 commits into
devfrom
puddly/windows-clean-close

Conversation

@puddly

@puddly puddly commented Jun 9, 2026

Copy link
Copy Markdown
Owner

The earlier fix we made for POSIX was also required for Win32. I've added a slow close test to catch more errors like this in the future, in addition to running the lifecycle test suite twice: once with eager task execution, once without.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.15%. Comparing base (fb3ef82) to head (4b21dd2).

Files with missing lines Patch % Lines
serialx/platforms/serial_win32.py 75.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #101      +/-   ##
==========================================
- Coverage   92.20%   92.15%   -0.05%     
==========================================
  Files          22       22              
  Lines        3654     3660       +6     
==========================================
+ Hits         3369     3373       +4     
- Misses        285      287       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the Win32 async transport close lifecycle with the POSIX behavior by ensuring handle-release work completes before protocol.connection_lost() is dispatched, and strengthens lifecycle regression coverage by running the suite under both lazy and eager task execution.

Changes:

  • Win32: defer connection_lost dispatch until after the underlying handle-close completes, stashing the loss reason meanwhile.
  • Tests: run async lifecycle tests twice (default vs eager task factory) and add a “slow close” regression test to assert connection_lost does not fire before the releasing syscall returns.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_async_lifecycle.py Adds eager-task parametrization and a slow-close lifecycle regression test.
serialx/platforms/serial_win32.py Reorders Win32 close/loss signaling to avoid races between closing and connection_lost.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_async_lifecycle.py
Comment thread serialx/platforms/serial_win32.py Outdated
@puddly puddly merged commit 4a1818c into dev Jun 9, 2026
38 of 40 checks passed
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