@@ -64,7 +64,7 @@ def connect(self, address: Tuple[str, int]) -> None:
64
64
try :
65
65
return self ._socket .connect (address , self ._mode )
66
66
except RuntimeError as error :
67
- raise OSError (errno .ENOMEM ) from error
67
+ raise OSError (errno .ENOMEM , str ( error ) ) from error
68
68
69
69
70
70
class _FakeSSLContext :
@@ -286,18 +286,23 @@ def get_socket(
286
286
host , port , 0 , self ._socket_pool .SOCK_STREAM
287
287
)[0 ]
288
288
289
+ first_exception = None
289
290
result = self ._get_connected_socket (
290
291
addr_info , host , port , timeout , is_ssl , ssl_context
291
292
)
292
293
if isinstance (result , Exception ):
293
294
# Got an error, if there are any available sockets, free them and try again
294
295
if self .available_socket_count :
296
+ first_exception = result
295
297
self ._free_sockets ()
296
298
result = self ._get_connected_socket (
297
299
addr_info , host , port , timeout , is_ssl , ssl_context
298
300
)
299
301
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
301
306
302
307
self ._key_by_managed_socket [result ] = key
303
308
self ._managed_socket_by_key [key ] = result
0 commit comments