Skip to content

Include 'timed out' messages in async network timeout exceptions - #1161

Closed
Kludex wants to merge 5 commits into
mainfrom
timeout-message
Closed

Include 'timed out' messages in async network timeout exceptions#1161
Kludex wants to merge 5 commits into
mainfrom
timeout-message

Conversation

@Kludex

@Kludex Kludex commented Aug 25, 2026

Copy link
Copy Markdown
Member

Closes #742.

AnyIO and Trio raise network timeout exceptions without messages. Map async read, write, and connect timeouts with explicit factories so they report timed out, matching the sync socket backend.

The generic exception mapper remains policy-free. Its mapping values now accept exception factories, allowing each backend to control the resulting exception message.

Pool timeouts are unchanged because they originate from connection-pool synchronization rather than a socket timeout, and both sync and async pool timeouts already have the same behavior.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

@Kludex
Kludex deployed to cloudflare August 25, 2026 12:52 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown

@codspeed-hq

codspeed-hq Bot commented Aug 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing timeout-message (0bea70c) with main (aaef581)

Open in CodSpeed

Footnotes

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/httpcore2/httpcore2/_backends/anyio.py">

<violation number="1" location="src/httpcore2/httpcore2/_backends/anyio.py:41">
P3: The fix only adds the "timed out" message to ReadTimeout, so async write/connect/pool timeouts remain inconsistent with sync. The same files still map TimeoutError/trio.TooSlowError to WriteTimeout (anyio.py write, line 48) and ConnectTimeout (anyio.py start_tls/connect_tcp/connect_unix_socket, trio.py equivalents) through map_exceptions, which passes the empty str(exc) as the message, while the sync backend's socket.timeout carries "timed out". If the goal is sync/async consistency for timeout messages, these paths need the same treatment (or the removal of the _exceptions.py 'timed out' handling should be reconsidered so it applies to all TimeoutException subclasses).</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/httpcore2/httpcore2/_backends/anyio.py Outdated
@Kludex Kludex changed the title Include 'timed out' message in async timeout exceptions Include 'timed out' messages in async network timeout exceptions Sep 4, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/httpcore2/httpcore2/_exceptions.py
Comment thread src/httpcore2/httpcore2/_backends/anyio.py Outdated
@Kludex

Kludex commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Closing as not planned. The exception type already identifies the timeout, and adding a synthetic message does not provide enough value to justify the additional mapping complexity.

@Kludex Kludex closed this Sep 4, 2026
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.

ReadTimeout in asyncio has no message

1 participant