[PR #12954/5c293f4f backport][3.14] Don't re-arm read timeout on a connection returned to the pool - #12966
Merged
Conversation
(cherry picked from commit 5c293f4)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.14 #12966 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 135 135
Lines 48625 48646 +21
Branches 2608 2609 +1
=======================================
+ Hits 47767 47788 +21
Misses 678 678
Partials 180 180
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #12954 as merged into master (5c293f4).
What do these changes do?
ResponseHandler.resume_reading()rescheduled thesock_readread timeout on every call. Butresume_reading()is also invoked while draining an already-buffered, completed response (StreamReader._read_nowait_chunk/feed_eof), which happens after the connection has been released to the keep-alive pool. That armed asock_readtimer on an idle pooled connection; the timer later fired, stamped aSocketTimeoutErroron the connection via_on_read_timeout, and the next request that reused the connection failed immediately (DataQueue.read()→raise self._exception), long before any realsock_readwindow.The fix only reschedules the read timeout when genuinely resuming a transport that was paused for backpressure (a read is still in flight). The in-flight read timeout is otherwise armed by
start_timeout()and refreshed indata_received(), so thisresume_reading()path was the only one that needed guarding. The parser-resume (data_received(b"")) used by the decompression-continuation path (#11966) is preserved.This restores the 3.13.5 behavior (where
resume_reading()only ran when the transport was actually paused).Are there changes in behavior for the user?
Yes — a regression introduced in 3.14 is fixed. Clients that set
ClientTimeout(sock_read=...)together with the keep-alive pool no longer get pooled connections poisoned by a stray read timeout, so reused connections stop failing with an immediateSocketTimeoutError. The exposure is worst whenkeepalive_timeout > sock_read. No public API change.Is it a substantial burden for the maintainers to support this?
No — the change is three lines, with a regression test. It narrows when the read timeout is rescheduled to match pre-3.14 semantics.
Related issue number
Fixes #12953
Checklist
CONTRIBUTORS.txtCHANGES/folderTest logs
Drafted with Claude Code (Opus 4.8); reviewed by @daragok.