@@ -255,17 +255,23 @@ async def open_connection(self, host, port, local_addr, lbind):
255255 if not self .streams .done ():
256256 await self .streams
257257 return self .streams .result ()
258- if self .direct :
259- if host == 'tunnel' :
260- raise Exception ('Unknown tunnel endpoint' )
261- local_addr = local_addr if lbind == 'in' else (lbind , 0 ) if lbind else None
262- wait = asyncio .open_connection (host = host , port = port , local_addr = local_addr )
263- elif self .unix :
264- wait = asyncio .open_unix_connection (path = self .bind , ssl = self .sslclient , server_hostname = '' if self .sslclient else None )
265- else :
266- local_addr = local_addr if self .lbind == 'in' else (self .lbind , 0 ) if self .lbind else None
267- wait = asyncio .open_connection (host = self .host_name , port = self .port , ssl = self .sslclient , local_addr = local_addr )
268- reader , writer = await asyncio .wait_for (wait , timeout = SOCKET_TIMEOUT )
258+ try :
259+ if self .direct :
260+ if host == 'tunnel' :
261+ raise Exception ('Unknown tunnel endpoint' )
262+ local_addr = local_addr if lbind == 'in' else (lbind , 0 ) if lbind else None
263+ wait = asyncio .open_connection (host = host , port = port , local_addr = local_addr )
264+ elif self .unix :
265+ wait = asyncio .open_unix_connection (path = self .bind , ssl = self .sslclient , server_hostname = '' if self .sslclient else None )
266+ else :
267+ local_addr = local_addr if self .lbind == 'in' else (self .lbind , 0 ) if self .lbind else None
268+ wait = asyncio .open_connection (host = self .host_name , port = self .port , ssl = self .sslclient , local_addr = local_addr )
269+ reader , writer = await asyncio .wait_for (wait , timeout = SOCKET_TIMEOUT )
270+ except Exception as ex :
271+ if self .reuse :
272+ self .streams .set_exception (ex )
273+ self .streams = None
274+ raise
269275 return reader , writer
270276 def prepare_connection (self , reader_remote , writer_remote , host , port ):
271277 if self .reuse and not self .handler :
0 commit comments