Skip to content

Add more async lifecycle tests and fix potential POSIX cancellation fd leak#93

Open
puddly wants to merge 14 commits into
devfrom
puddly/fix-descriptor-transport-cancellation-leak
Open

Add more async lifecycle tests and fix potential POSIX cancellation fd leak#93
puddly wants to merge 14 commits into
devfrom
puddly/fix-descriptor-transport-cancellation-leak

Conversation

@puddly
Copy link
Copy Markdown
Owner

@puddly puddly commented May 15, 2026

This PR adds an explicit test suite for the asyncio.Protocol state machine pattern and aligns platform behavior around poorly-timed cancellation. These aren't things normally hit at runtime often but it's not good practice to leak file descriptors, especially when we use flock.

We also plug a few more cancellation point leaks. This pattern is a bit annoying to deal with because any await point can potentially be cancelled but with the asterisk that we are often awaiting on the result of a thread pool executor, which cannot be cancelled. This requires a bit of coordination with future callbacks and such.

For Windows, we now intentionally detach the file handle from PyHANDLE and let it "leak" for consistency with POSIX, since the cleanup code should work without a magical __del__.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 93.84615% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.21%. Comparing base (b068974) to head (96c29c3).

Files with missing lines Patch % Lines
serialx/platforms/serial_rfc2217/__init__.py 81.81% 2 Missing ⚠️
serialx/platforms/serial_win32.py 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #93      +/-   ##
==========================================
+ Coverage   91.46%   92.21%   +0.74%     
==========================================
  Files          22       22              
  Lines        3599     3621      +22     
==========================================
+ Hits         3292     3339      +47     
+ Misses        307      282      -25     

☔ View full report in Codecov by Sentry.
📢 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.

@puddly puddly marked this pull request as ready for review May 15, 2026 20:35
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