Reject ClientTimeout(total=0) in v4, use None to disable timeouts#12044
Reject ClientTimeout(total=0) in v4, use None to disable timeouts#12044Dreamsorcerer merged 6 commits intoaio-libs:masterfrom
Conversation
Merging this PR will not alter performance
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12044 +/- ##
==========================================
+ Coverage 98.69% 98.76% +0.06%
==========================================
Files 127 127
Lines 44667 44684 +17
Branches 2372 2372
==========================================
+ Hits 44086 44130 +44
+ Misses 412 393 -19
+ Partials 169 161 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
According to the issue, Sam suggested not supporting this in v4. |
|
Right -- Sam mentioned considering removing Happy to add a deprecation warning for |
If we're good with dropping support for 0, then I'd like this PR to be moved to the 3.14 branch, and a new PR to master (v4) that removes it. |
|
Makes sense, I'll retarget this to the 3.14 branch with the fix + deprecation warning for |
|
Created #12067 against the 3.14 branch with the normalization fix. I'll rework this PR to remove |
When `ClientTimeout(total=0)` is used (meaning no timeout), the value `0` was passed directly to `asyncio.loop.start_tls()` as `ssl_handshake_timeout`, which requires either `None` or a positive number. This caused a `ValueError`. The fix converts `0` to `None` using `timeout.total or None` before passing it to `start_tls()`, aligning with aiohttp's documented behavior where both `None` and `0` mean "no timeout". Fixes aio-libs#11859 Co-Authored-By: Claude Opus 4.6 <[email protected]>
…loop.start_tls The Python intersphinx inventory lists asyncio.loop.start_tls as a py:method, not py:func. Using :py:func: causes an unresolved reference warning, which fails the build due to Sphinx's -W flag. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Rewrite test_start_tls_with_zero_total_timeout to use a real TLS server/client instead of mocking internals. This tests actual framework behavior — making an HTTPS request with ClientTimeout(total=0) should succeed without raising ValueError. Also fix changelog to use :exc: Sphinx reference for ValueError.
Instead of normalizing 0 to None for ssl_handshake_timeout, validate upfront that total=0 is not passed. The docs previously said 0 or None disables the timeout, but asyncio.loop.start_tls only accepts None or positive values. For v4, we drop the 0 support entirely with a clear error message directing users to use None instead. Fixes aio-libs#11859
cbdf743 to
8972966
Compare
|
Reworked this for v4 as discussed. Instead of normalizing
The 3.14 backport (#12067) keeps the normalization approach for backwards compatibility. |
|
Appears to be a test to update. |
The test_tcp_connector_cancel_dns_error_captured test was still using ClientTimeout(0) which now raises ValueError since total=0 is no longer supported. Use default ClientTimeout() (total=None) instead.
|
Updated the test, thanks for pointing that out. |
|
Hi @Dreamsorcerer @webknjaz, this has been reworked for v4 as discussed — ClientTimeout now rejects total=0 in post_init with a clear error pointing to None, and I've updated the test that was flagged. The 3.14 backport is in #12067. Ready for another look when you get a chance! |
Fixes #11859
Instead of normalizing
total=0toNone, this PR removes support forClientTimeout(total=0)entirely in v4.asyncio.loop.start_tls()only acceptsNoneor a positive number forssl_handshake_timeout, so passingtotal=0caused aValueError. Rather than working around it, we now rejecttotal=0upfront with a clear error message directing users to useNoneinstead.The backport to 3.14 (#12067) keeps the normalization approach for backwards compatibility.
Changes:
__post_init__validation toClientTimeoutthat rejectstotal=0timeout.total or Noneworkaround inconnector.py