Jump to solution
Verify

The Fix

pip install urllib3==2.2.0

Based on closed urllib3/urllib3 issue #2991 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -348,7 +348,8 @@ async def pyodide_upload() -> ResponseTypes: if file.filename != "lolcat.txt": return await make_response(f"File name incorrect {file.name}", 404) - data = file.read().decode("utf-8") + with contextlib.closing(file): + data = file.read().decode("utf-8")
repro.py
import sys import urllib3 import pytest import gc def main(): with urllib3.HTTPSConnectionPool( "google.com", 443, assert_fingerprint=( "AA:AA:AA:AA:AA:AAAA:AA:AAAA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA" ), ) as https_pool: with pytest.raises(urllib3.exceptions.MaxRetryError): https_pool.request("GET", "/", retries=0) if __name__ == "__main__": sys.exit(main())
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install urllib3==2.2.0\nWhen NOT to use: Do not use this fix if the application relies on keeping sockets open for reuse.\n\n

Why This Fix Works in Production

  • Trigger: ResourceWarning due to _ssl_wrap_socket_and_match_hostname assert_fingerprint or assert_hostname failures not closing socket
  • Mechanism: The SSL socket was not closed properly on assertion failures, leading to ResourceWarnings
  • Why the fix works: Ensures that the SSL socket is closed if the assert_fingerprint or assert_hostname checks fail, preventing ResourceWarnings. (first fixed release: 2.2.0).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • The SSL socket was not closed properly on assertion failures, leading to ResourceWarnings
  • Production symptom (often without a traceback): ResourceWarning due to _ssl_wrap_socket_and_match_hostname assert_fingerprint or assert_hostname failures not closing socket

Proof / Evidence

  • GitHub issue: #2991
  • Fix PR: https://github.com/urllib3/urllib3/pull/2842
  • First fixed release: 2.2.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.75
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.61

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“### Subject ResourceWarning due to _ssl_wrap_socket_and_match_hostname assert_fingerprint or assert_hostname failures not closing socket discovered using https://github.com/urllib3/urllib3/pull/2842 ### Environment Describe your environment”
Issue thread · issue description · source

Failure Signature (Search String)

  • ResourceWarning due to _ssl_wrap_socket_and_match_hostname assert_fingerprint or assert_hostname failures not closing socket
  • assert_fingerprint=(
Copy-friendly signature
signature.txt
Failure Signature ----------------- ResourceWarning due to _ssl_wrap_socket_and_match_hostname assert_fingerprint or assert_hostname failures not closing socket assert_fingerprint=(

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- ResourceWarning due to _ssl_wrap_socket_and_match_hostname assert_fingerprint or assert_hostname failures not closing socket assert_fingerprint=(

Minimal Reproduction

repro.py
import sys import urllib3 import pytest import gc def main(): with urllib3.HTTPSConnectionPool( "google.com", 443, assert_fingerprint=( "AA:AA:AA:AA:AA:AAAA:AA:AAAA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA" ), ) as https_pool: with pytest.raises(urllib3.exceptions.MaxRetryError): https_pool.request("GET", "/", retries=0) if __name__ == "__main__": sys.exit(main())

What Broke

ResourceWarnings were raised due to unclosed SSL sockets during connection failures.

Why It Broke

The SSL socket was not closed properly on assertion failures, leading to ResourceWarnings

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install urllib3==2.2.0

When NOT to use: Do not use this fix if the application relies on keeping sockets open for reuse.

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/2842

First fixed release: 2.2.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if the application relies on keeping sockets open for reuse.

Verify Fix

verify
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

VersionStatus
2.2.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.