diff options
| author | Ran Benita <ran@unusedvar.com> | 2021-06-19 17:42:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-19 09:42:44 -0500 |
| commit | 195b24b1bc692fe95b03f871900e09f2ea19376d (patch) | |
| tree | 60179355efd7c4d607950dd347cf7670219c7482 /src | |
| parent | b0ef7fbd21a9481c6d7a7c516c7974d64142ee9c (diff) | |
| download | urllib3-195b24b1bc692fe95b03f871900e09f2ea19376d.tar.gz | |
Add cycle-breaking logic to create_connection()
This commit synchronizes create_connection() with the implementation in the socket module
Diffstat (limited to 'src')
| -rw-r--r-- | src/urllib3/util/connection.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/urllib3/util/connection.py b/src/urllib3/util/connection.py index 21ec8ecf..5f4be134 100644 --- a/src/urllib3/util/connection.py +++ b/src/urllib3/util/connection.py @@ -74,18 +74,23 @@ def create_connection( if source_address: sock.bind(source_address) sock.connect(sa) + # Break explicitly a reference cycle + err = None return sock - except OSError as e: - err = e + except OSError as _: + err = _ if sock is not None: sock.close() - sock = None if err is not None: - raise err - - raise OSError("getaddrinfo returns an empty list") + try: + raise err + finally: + # Break explicitly a reference cycle + err = None + else: + raise OSError("getaddrinfo returns an empty list") def _set_socket_options(sock: socket.socket, options: Optional[SocketOptions]) -> None: |
