Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync create_connection with socket module #2277

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Sync create_connection with socket module
Bring in cycle-breaking which reduces garbage for the GC.
  • Loading branch information
bluetech committed Jun 18, 2021
commit e0e4866f2989d705afd569b76ebf5baf0dd36a16
17 changes: 11 additions & 6 deletions src/urllib3/util/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down