File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -307,14 +307,15 @@ def handle_request(self, request: Request) -> Response:
307307 alpn_protocols = ["http/1.1" , "h2" ] if self ._http2 else ["http/1.1" ]
308308 ssl_context .set_alpn_protocols (alpn_protocols )
309309
310- kwargs = {
311- "ssl_context" : ssl_context ,
312- "server_hostname" : self ._remote_origin .host .decode ("ascii" ),
313- "timeout" : timeout ,
314- }
315- with Trace ("start_tls" , logger , request , kwargs ) as trace :
316- stream = stream .start_tls (** kwargs )
317- trace .return_value = stream
310+ try :
311+ with Trace ("start_tls" , logger , request , kwargs ) as trace :
312+ stream = stream .start_tls (** kwargs )
313+ trace .return_value = stream
314+ except Exception :
315+ # Close the underlying connection when TLS handshake fails to avoid
316+ # zombie connections occupying the connection pool
317+ self ._connection .close ()
318+ raise
318319
319320 # Determine if we should be using HTTP/1.1 or HTTP/2
320321 ssl_object = stream .get_extra_info ("ssl_object" )
You can’t perform that action at this time.
0 commit comments