[3.6] bpo-31234, socket.create_connection(): Fix ref cycle (GH-3546) … · python/cpython@d99e85b

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -711,6 +711,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,

711711

if source_address:

712712

sock.bind(source_address)

713713

sock.connect(sa)

714+

# Break explicitly a reference cycle

715+

err = None

714716

return sock

715717
716718

except error as _:

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,2 @@

1+

socket.create_connection() now fixes manually a reference cycle: clear the

2+

variable storing the last exception on success.