diff --git a/src/anyio/_core/_sockets.py b/src/anyio/_core/_sockets.py index adcbd7f9..a225e6b9 100644 --- a/src/anyio/_core/_sockets.py +++ b/src/anyio/_core/_sockets.py @@ -223,11 +223,13 @@ async def try_connect(remote_host: str, event: Event) -> None: cause = ( oserrors[0] if len(oserrors) == 1 - else ExceptionGroup("multiple connection attempts failed", oserrors) + else ExceptionGroup( + "multiple connection attempts failed", oserrors.copy() + ) ) raise OSError("All connection attempts failed") from cause finally: - oserrors = [] + oserrors.clear() if tls or tls_hostname or ssl_context: try: