The Fix
pip install urllib3==1.25.9
Based on closed urllib3/urllib3 issue #1883 · PR/commit linked
Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.
@@ -300,5 +300,8 @@ In chronological order:
* Fix for connection not being released on HTTP redirect and response not preloaded
+* [Bastiaan Bakker] <https://github.com/bastiaanb>
+ * Support for logging session keys via environment variable ``SSLKEYLOGFILE`` (Python 3.8+)
+
2020-05-31T04:32:39.1658820Z ________ TestSocketClosing.test_delayed_body_read_timeout_with_preload _________
2020-05-31T04:32:39.1659980Z Traceback (most recent call last):
2020-05-31T04:32:39.1663620Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connection.py", line 159, in _new_conn
2020-05-31T04:32:39.1664020Z (self._dns_host, self.port), self.timeout, **extra_kw
2020-05-31T04:32:39.1665550Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
2020-05-31T04:32:39.1665760Z raise err
2020-05-31T04:32:39.1666450Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection
2020-05-31T04:32:39.1666640Z sock.connect(sa)
2020-05-31T04:32:39.1666770Z ConnectionRefusedError: [Errno 61] Connection refused
2020-05-31T04:32:39.1666830Z
2020-05-31T04:32:39.1666950Z During handling of the above exception, another exception occurred:
2020-05-31T04:32:39.1667010Z
2020-05-31T04:32:39.1667140Z Traceback (most recent call last):
2020-05-31T04:32:39.1667370Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/test/with_dummyserver/test_socketlevel.py", line 570, in test_delayed_body_read_timeout_with_preload
2020-05-31T04:32:39.1667540Z pool.urlopen("GET", "/", retries=False, timeout=timeout)
2020-05-31T04:32:39.1668150Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
2020-05-31T04:32:39.1668340Z method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
2020-05-31T04:32:39.1668950Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
2020-05-31T04:32:39.1669170Z raise six.reraise(type(error), error, _stacktrace)
2020-05-31T04:32:39.1669840Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/packages/six.py", line 735, in reraise
2020-05-31T04:32:39.1669990Z raise value
2020-05-31T04:32:39.1670620Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
2020-05-31T04:32:39.1670770Z chunked=chunked,
2020-05-31T04:32:39.1671360Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
2020-05-31T04:32:39.1671540Z conn.request(method, url, **httplib_request_kw)
2020-05-31T04:32:39.1671720Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1252, in request
2020-05-31T04:32:39.1671870Z self._send_request(method, url, body, headers, encode_chunked)
2020-05-31T04:32:39.1672060Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1298, in _send_request
2020-05-31T04:32:39.1672200Z self.endheaders(body, encode_chunked=encode_chunked)
2020-05-31T04:32:39.1672390Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1247, in endheaders
2020-05-31T04:32:39.1672510Z self._send_output(message_body, encode_chunked=encode_chunked)
2020-05-31T04:32:39.1673070Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1026, in _send_output
2020-05-31T04:
... (truncated) ...
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.25.9\nWhen NOT to use: This fix should not be applied if the flaky behavior is due to actual network issues.\n\n
Why This Fix Works in Production
- Trigger: ConnectionRefusedError: [Errno 61] Connection refused
- Mechanism: The flaky test 'test_delayed_body_read_timeout_with_preload' is caused by intermittent connection issues during testing
- Why the fix works: The issue regarding the flaky test 'test_delayed_body_read_timeout_with_preload' has been noted, but no specific fix was implemented in a PR that closes the issue. (first fixed release: 1.25.9).
- If left unfixed, tail latency can spike under load and surface as timeouts/retries (amplifying incident impact).
Why This Breaks in Prod
- Shows up under Python 3.7 in real deployments (not just unit tests).
- The flaky test 'test_delayed_body_read_timeout_with_preload' is caused by intermittent connection issues during testing
- Surfaces as: ConnectionRefusedError: [Errno 61] Connection refused
Proof / Evidence
- GitHub issue: #1883
- Fix PR: https://github.com/urllib3/urllib3/pull/1867
- First fixed release: 1.25.9
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.46
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I haven't seen this test being as flaky lately (at least any more than any other timeout test?) so I'm going to close this. Let…”
“I think it's still flaky but this issue isn't helping.”
Failure Signature (Search String)
- ConnectionRefusedError: [Errno 61] Connection refused
Error Message
Stack trace
Error Message
-------------
ConnectionRefusedError: [Errno 61] Connection refused
Minimal Reproduction
2020-05-31T04:32:39.1658820Z ________ TestSocketClosing.test_delayed_body_read_timeout_with_preload _________
2020-05-31T04:32:39.1659980Z Traceback (most recent call last):
2020-05-31T04:32:39.1663620Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connection.py", line 159, in _new_conn
2020-05-31T04:32:39.1664020Z (self._dns_host, self.port), self.timeout, **extra_kw
2020-05-31T04:32:39.1665550Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
2020-05-31T04:32:39.1665760Z raise err
2020-05-31T04:32:39.1666450Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection
2020-05-31T04:32:39.1666640Z sock.connect(sa)
2020-05-31T04:32:39.1666770Z ConnectionRefusedError: [Errno 61] Connection refused
2020-05-31T04:32:39.1666830Z
2020-05-31T04:32:39.1666950Z During handling of the above exception, another exception occurred:
2020-05-31T04:32:39.1667010Z
2020-05-31T04:32:39.1667140Z Traceback (most recent call last):
2020-05-31T04:32:39.1667370Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/test/with_dummyserver/test_socketlevel.py", line 570, in test_delayed_body_read_timeout_with_preload
2020-05-31T04:32:39.1667540Z pool.urlopen("GET", "/", retries=False, timeout=timeout)
2020-05-31T04:32:39.1668150Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
2020-05-31T04:32:39.1668340Z method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
2020-05-31T04:32:39.1668950Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
2020-05-31T04:32:39.1669170Z raise six.reraise(type(error), error, _stacktrace)
2020-05-31T04:32:39.1669840Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/packages/six.py", line 735, in reraise
2020-05-31T04:32:39.1669990Z raise value
2020-05-31T04:32:39.1670620Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
2020-05-31T04:32:39.1670770Z chunked=chunked,
2020-05-31T04:32:39.1671360Z File "/Users/runner/runners/2.263.0/work/urllib3/urllib3/.nox/test-3-7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
2020-05-31T04:32:39.1671540Z conn.request(method, url, **httplib_request_kw)
2020-05-31T04:32:39.1671720Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1252, in request
2020-05-31T04:32:39.1671870Z self._send_request(method, url, body, headers, encode_chunked)
2020-05-31T04:32:39.1672060Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1298, in _send_request
2020-05-31T04:32:39.1672200Z self.endheaders(body, encode_chunked=encode_chunked)
2020-05-31T04:32:39.1672390Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1247, in endheaders
2020-05-31T04:32:39.1672510Z self._send_output(message_body, encode_chunked=encode_chunked)
2020-05-31T04:32:39.1673070Z File "/Users/runner/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/http/client.py", line 1026, in _send_output
2020-05-31T04:
... (truncated) ...
Environment
- Python: 3.7
What Broke
Intermittent test failures leading to unreliable CI results and potential delays in development.
Why It Broke
The flaky test 'test_delayed_body_read_timeout_with_preload' is caused by intermittent connection issues during testing
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install urllib3==1.25.9
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/1867
First fixed release: 1.25.9
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the flaky behavior is due to actual network issues.
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.
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
Version Compatibility Table
| Version | Status |
|---|---|
| 1.25.9 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.