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
Getting SSL: WRONG_VERSION_NUMBER randomly. A restart resolves for a couple of days. #3713
We have an python application using httpx (v0.27.0). The applications uses httpx to open https connecto to AWS api gateway. This has been stable and working for years. Recently we will see a random error on connection:
httpcore.ConnectError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1000)
The error is intermittent. Some requests work and some don't. There is only one instance of this app in ECS so it is not load balancing issue. The strange part if we restart the docker container with this python app the issue gets resolved for a few days and then slowly creeps back.
It is almost like something is being chached or pooled. However, from documentation we don't see anything that would cause this. We use default httpx client settings.
Hi @konstantin-shatalov , I've encountered this issue before. Hope this works for you:
The [SSL: WRONG_VERSION_NUMBER] error pattern you're experiencing is likely caused by stale connections in httpx's connection pool:
httpx maintains an HTTP connection pool with idle connections
AWS API Gateway/load balancer silently closes these connections after some idle time
httpx reuses a connection from its pool that AWS has already closed
When trying to send data over this closed connection, the SSL layer gets gibberish/RST packet instead of a proper TLS handshake: WRONG_VERSION_NUMBER error
The fact that it "slowly creeps back" after restart strongly supports this - connections start fresh, then gradually become stale over time.
Possible solution:
Reduce keepalive_expiry. Configure httpx to expire idle connections faster than AWS closes them
You can also disable the connection pooling. Trade-off: Slower (new TLS handshake for every request) but eliminates stale connections.
Activity
rodrigobnogueira commentedon Jan 15, 2026
Hi @konstantin-shatalov , I've encountered this issue before. Hope this works for you:
The [SSL: WRONG_VERSION_NUMBER] error pattern you're experiencing is likely caused by stale connections in httpx's connection pool:
The fact that it "slowly creeps back" after restart strongly supports this - connections start fresh, then gradually become stale over time.
Possible solution:
Reduce
keepalive_expiry. Configure httpx to expire idle connections faster than AWS closes themYou can also disable the connection pooling. Trade-off: Slower (new TLS handshake for every request) but eliminates stale connections.
Or... implement a retry logic
Improve SSL error message with helpful hints (encode#3713)
Improve SSL error message with helpful hints (encode#3713)