@@ -64,7 +64,7 @@ def connect(self, address: Tuple[str, int]) -> None:
6464 try :
6565 return self ._socket .connect (address , self ._mode )
6666 except RuntimeError as error :
67- raise OSError (errno .ENOMEM ) from error
67+ raise OSError (errno .ENOMEM , str ( error ) ) from error
6868
6969
7070class _FakeSSLContext :
@@ -286,18 +286,23 @@ def get_socket(
286286 host , port , 0 , self ._socket_pool .SOCK_STREAM
287287 )[0 ]
288288
289+ first_exception = None
289290 result = self ._get_connected_socket (
290291 addr_info , host , port , timeout , is_ssl , ssl_context
291292 )
292293 if isinstance (result , Exception ):
293294 # Got an error, if there are any available sockets, free them and try again
294295 if self .available_socket_count :
296+ first_exception = result
295297 self ._free_sockets ()
296298 result = self ._get_connected_socket (
297299 addr_info , host , port , timeout , is_ssl , ssl_context
298300 )
299301 if isinstance (result , Exception ):
300- raise RuntimeError (f"Error connecting socket: { result } " ) from result
302+ last_result = f", first error: { first_exception } " if first_exception else ""
303+ raise RuntimeError (
304+ f"Error connecting socket: { result } { last_result } "
305+ ) from result
301306
302307 self ._key_by_managed_socket [result ] = key
303308 self ._managed_socket_by_key [key ] = result
0 commit comments