The Fix
pip install urllib3==1.25.4
Based on closed urllib3/urllib3 issue #1623 · 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%.
@@ -6,8 +6,8 @@ tornado==5.1.1
pkginfo==1.4.2
pytest-timeout==1.3.1
-pytest==3.8.2
-pluggy==0.8.0
+pytest==4.0.0
import pytest
@pytest.fixture
def pool_manager():
manager = PoolManager()
try:
yield manager
finally:
manager.clear()
def test_redirect(pool_manager):
r = http.request("GET", "/redirect", ...)
assert r.status == 303
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.4\nWhen NOT to use: This fix is inappropriate if maintaining unittest compatibility is required.\n\n
Why This Fix Works in Production
- Trigger: * the current code does not work with pytest>=4.2 (possibly a bug in pytest)
- Mechanism: Stops using unittest's addCleanup in favor of pytest fixtures, improving test clarity and compatibility.
- Why the fix works: Stops using unittest's addCleanup in favor of pytest fixtures, improving test clarity and compatibility. (first fixed release: 1.25.4).
- 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
- Production symptom (often without a traceback): * the current code does not work with pytest>=4.2 (possibly a bug in pytest)
Proof / Evidence
- GitHub issue: #1623
- Fix PR: https://github.com/urllib3/urllib3/pull/1614
- First fixed release: 1.25.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.72
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Closing this issue now that #1624 has landed. Reopen if I'm wrong.”
“I almost want to go all the way and say that PoolManager should implement the context manager protocol because (correct me if I'm wrong) a…”
“ConnectionPool class has implemented the context manager protocol https://github.com/urllib3/urllib3/blob/master/src/urllib3/connectionpool.py#L82-L85 and the HTTPConnectionPool class inherits from it and HTTPSConnectionPool is subclass of HTTPConnectionPool P”
Failure Signature (Search String)
- * the current code does not work with pytest>=4.2 (possibly a bug in pytest)
- assert r.status == 303
Copy-friendly signature
Failure Signature
-----------------
* the current code does not work with pytest>=4.2 (possibly a bug in pytest)
assert r.status == 303
Error Message
Signature-only (no traceback captured)
Error Message
-------------
* the current code does not work with pytest>=4.2 (possibly a bug in pytest)
assert r.status == 303
Minimal Reproduction
import pytest
@pytest.fixture
def pool_manager():
manager = PoolManager()
try:
yield manager
finally:
manager.clear()
def test_redirect(pool_manager):
r = http.request("GET", "/redirect", ...)
assert r.status == 303
What Broke
Tests fail to clean up resources, leading to resource leaks and flaky tests.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install urllib3==1.25.4
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option D — Guard side-effects with OnceOnly Guardrail for side-effects
Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.
- Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
- Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
- Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
from onceonly import OnceOnly
import os
once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True)
# Stable idempotency key per real side-effect.
# Use a request id / job id / webhook delivery id / Stripe event id, etc.
event_id = "evt_..." # replace
key = f"stripe:webhook:{event_id}"
res = once.check_lock(key=key, ttl=3600)
if res.duplicate:
return {"status": "already_processed"}
# Safe to execute the side-effect exactly once.
handle_event(event_id)
Fix reference: https://github.com/urllib3/urllib3/pull/1614
First fixed release: 1.25.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is inappropriate if maintaining unittest compatibility is required.
- Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.
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.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.