Skip to content

Translate backend EOF errors into ProxyError - #53

Merged
romis2012 merged 2 commits into
romis2012:masterfrom
Quinnod345:fix/backend-eof-errors
Nov 18, 2026
Merged

romis2012 merged 2 commits into
romis2012:masterfrom
Quinnod345:fix/backend-eof-errors

Conversation

@Quinnod345

Copy link
Copy Markdown
Contributor

AnyIO v1 catches the stdlib incomplete-read exception, but its stream raises the package exception. Asyncio v2 has the reverse mismatch. A peer closing during negotiation therefore bypasses the intended ProxyError conversion.

Catch each stream's actual EOF type. Keep AnyIO's existing shielded cleanup behavior when moving EOF into its specific handler. The regression uses the public proxy APIs with both AnyIO backends and asyncio v2. It covers truncated replies, protocol errors, successful tunnels and cancellation.

Local validation against upstream 8d054e5855e354735b95f2004d9fe8242920e261:

  • The same final regression has 14 failures and 12 passing controls on upstream. Correcting only the exception imports leaves 2 close-cancellation failures and 24 passes. The complete fix passes all 26 cases.
  • All 429 project tests pass on macOS with CPython 3.14.7, AnyIO 4.16.0 and Trio 0.35.0. That run used owned loopback fixtures with ephemeral ports and runtime URL data.
  • Ruff and formatting pass. Focused Mypy passes 60 files. Full Mypy reports three errors in unchanged test helpers; pristine upstream has the same diagnostics in this environment.

Other Python versions, operating systems and hosted CI were not run locally. The close-cancellation regression uses an owned asynchronous test stream; it does not demonstrate a native transport leak.

I maintain Ponder. Its review flagged the mismatched EOF handlers and helped check cleanup preservation. I implemented the patch and ran the checks above.

Catch the actual incomplete-read types produced by AnyIO v1 and asyncio
v2. Preserve AnyIO's shielded EOF cleanup while using its specific handler.

Add truncation, protocol-error, success and cancellation regressions.
The identical 26 cases fail 14 times on upstream and pass with this fix.
Owned-loopback project validation passes 429 tests on macOS Python 3.14;
full Mypy retains three unchanged upstream test-helper diagnostics.
@romis2012

romis2012 commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

In asyncio v2 we should handle python_socks._errors.IncompleteReadError (not asyncio.IncompleteReadError) for consistency.
At the same time we should catch asyncio.IncompleteReadError and raise python_socks._errors.IncompleteReadError in python_socks.async_.asyncio.v2._stream.AsyncioSocketStream.read_exactly

Translate the asyncio error in read_exactly and keep the original exception as its cause. Catch the package error in the proxy after the existing cleanup. Keep the cancellation type and cleanup assertions on every supported Python version and check the message where asyncio propagates it.
@Quinnod345

Copy link
Copy Markdown
Contributor Author

Addressed in 4c20b38. The asyncio v2 stream translates a short read to the package IncompleteReadError and preserves the original asyncio error as its cause. The proxy catches the package error and closes the stream as before. The cancellation test still checks cancellation and cleanup on every supported Python version, with the message assertion on 3.11 and later.

Python 3.14.7 passed 429 tests, Ruff, and Mypy. All 26 focused tests passed on Python 3.9.25.

I maintain Ponder and used it to review this follow-up.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.22%. Comparing base (8d054e5) to head (4c20b38).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #53      +/-   ##
==========================================
+ Coverage   94.38%   95.22%   +0.84%     
==========================================
  Files          55       55              
  Lines        1566     1570       +4     
==========================================
+ Hits         1478     1495      +17     
+ Misses         88       75      -13     
Flag Coverage Δ
unit 95.22% <100.00%> (+0.84%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@romis2012
romis2012 merged commit 5813eea into romis2012:master Nov 18, 2026
7 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.

3 participants