The Fix
pip install urllib3==1.26.13
Based on closed urllib3/urllib3 issue #2645 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
+Fixed an issue where an ``HTTPConnection`` instance would erroneously reuse the socket
+read timeout value from reading the previous response instead of a newly configured connect timeout.
+Instead now if ``HTTPConnection.timeout`` is updated before sending the next request the new timeout value will be used.
import time
import urllib3
from urllib3.util import Timeout
TOKEN = "uploadtoken"
BASE_URL = "http://upload-server"
# BASE_URL = "https://upload-server" # Fails for HTTPS too when using stdlib SSLContext but not PyOpenSSLContext
http = urllib3.PoolManager(cert_reqs='CERT_NONE')
# 1. Seed the timeout on the conn
r = http.request("GET", f"{BASE_URL}/files/test.txt?token={TOKEN}", timeout=Timeout(connect=5, read=6))
# 2. Upload file that takes >5 seconds to complete
# 500MB file at 500mbps bandwidth uploads in ~10.5s with the following code
with open("/var/data-for-upload/500MB.bin") as fp:
file_data = fp.read()
upload_start = time.time()
try:
r = http.request("POST", f"{BASE_URL}/upload?token={TOKEN}", fields={"file": ("500MB.bin", file_data)}, timeout=15)
finally:
print(f"Upload request finished in {time.time() - upload_start:.3f} seconds")
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install urllib3==1.26.13\nWhen NOT to use: This fix should not be applied if using a custom socket management strategy.\n\n
Why This Fix Works in Production
- Trigger: urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError('The write operation timed out'))
- Mechanism: The HTTPConnection instance reused the socket read timeout from the previous response instead of applying a new connect timeout
- Why the fix works: Fixes the socket timeout value when reusing an HTTPConnection, ensuring the new timeout is applied correctly. (first fixed release: 1.26.13).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.10.5 in real deployments (not just unit tests).
- The HTTPConnection instance reused the socket read timeout from the previous response instead of applying a new connect timeout
- Surfaces as: urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError('The write operation timed out'))
Proof / Evidence
- GitHub issue: #2645
- Fix PR: https://github.com/urllib3/urllib3/pull/2792
- First fixed release: 1.26.13
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.35
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@nickwilliams-zaxiom If you could submit a backport PR we can discuss including it as a bug fix for that release stream.”
“@SethMichaelLarson, I see that this has been fixed, but was not included in 1.26.13. This issue is currently affecting me as well. Is there a…”
“@sethmlarson, I have submitted the PR as requested. I have a comment in there about the GH action failures as well. Let me know how…”
Failure Signature (Search String)
- urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError('The write operation timed out'))
Error Message
Stack trace
Error Message
-------------
urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError('The write operation timed out'))
Stack trace
Error Message
-------------
Upload request finished in 6.317 seconds
Traceback (most recent call last):
File "/home/urllib3/src/urllib3/connectionpool.py", line 727, in urlopen
httplib_response = self._make_request(
File "/home/urllib3/src/urllib3/connectionpool.py", line 433, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/urllib3/src/urllib3/connection.py", line 309, in request
super().request(method, url, body=body, headers=headers)
File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1076, in _send_output
self.send(chunk)
File "/usr/local/lib/python3.10/http/client.py", line 998, in send
self.sock.sendall(data)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/bug-bait-simple.py", line 22, in <module>
r = http.request("POST", f"{BASE_URL}/upload?token={TOKEN}", fields={"file": ("500MB.bin", file_data)}, timeout=15)
File "/home/urllib3
... (truncated) ...
Minimal Reproduction
import time
import urllib3
from urllib3.util import Timeout
TOKEN = "uploadtoken"
BASE_URL = "http://upload-server"
# BASE_URL = "https://upload-server" # Fails for HTTPS too when using stdlib SSLContext but not PyOpenSSLContext
http = urllib3.PoolManager(cert_reqs='CERT_NONE')
# 1. Seed the timeout on the conn
r = http.request("GET", f"{BASE_URL}/files/test.txt?token={TOKEN}", timeout=Timeout(connect=5, read=6))
# 2. Upload file that takes >5 seconds to complete
# 500MB file at 500mbps bandwidth uploads in ~10.5s with the following code
with open("/var/data-for-upload/500MB.bin") as fp:
file_data = fp.read()
upload_start = time.time()
try:
r = http.request("POST", f"{BASE_URL}/upload?token={TOKEN}", fields={"file": ("500MB.bin", file_data)}, timeout=15)
finally:
print(f"Upload request finished in {time.time() - upload_start:.3f} seconds")
Environment
- Python: 3.10.5
What Broke
Subsequent requests fail with a timeout error due to the original request's timeout settings.
Why It Broke
The HTTPConnection instance reused the socket read timeout from the previous response instead of applying a new connect timeout
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install urllib3==1.26.13
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/urllib3/urllib3/pull/2792
First fixed release: 1.26.13
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if using a custom socket management strategy.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
- Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
Version Compatibility Table
| Version | Status |
|---|---|
| 1.26.13 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.