You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The create_ssl_context() call can consume a lot of memory #3734
Based on researching this bug in Python, the create_ssl_context() calls can consume a lot of memory (10s or 100s of megabytes). This problem is made worse by the reference cycles created by BoundSyncStream and BoundAsyncStream (I expect they are keeping the SSL context alive).
It would seem prudent to investigate if the default context can be shared between connections (e.g. use a cache?). The script that shows high memory usage is pretty trivial:
It seems that both "pip" and "requests" re-use the context, see: pypa/pip#13199. One potential issue with caching it is that if the certificate store is updated after caching, the update will not be seen unless the Python program is restarted or if the cache has some kind of invalidation or timeout.
SSL context memory bloat is a known issue, especially with many connections.
Workarounds:
Reuse SSL context:
importsslimporthttpx# Create once, reusessl_context=ssl.create_default_context()
asyncwithhttpx.AsyncClient(verify=ssl_context) asclient:
# All requests share the same contextforurlinurls:
awaitclient.get(url)
Activity
nascheme commentedon Dec 29, 2025
It seems that both "pip" and "requests" re-use the context, see: pypa/pip#13199. One potential issue with caching it is that if the certificate store is updated after caching, the update will not be seen unless the Python program is restarted or if the cache has some kind of invalidation or timeout.
Fix SSL context memory issue by breaking reference cycles (encode#3734)
rodrigobnogueira commentedon Jan 15, 2026
PR #3733 seems to solve this issue
xXMrNidaXx commentedon Feb 25, 2026
SSL context memory bloat is a known issue, especially with many connections.
Workarounds:
What's your usage pattern? Many unique hosts or repeated connections?
🔧 Building high-performance APIs? We're hiring at RevolutionAI:
https://www.revolutionai.io/find-work
Production AI projects • Great rates 💼