diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-03 22:13:31 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-03 22:13:31 (GMT) |
commit | b470f0dd2a4a539bb8ba44c818f685fb9a260d38 (patch) | |
tree | c25572fef36655186c2e0f7e164d4b08e455125d /Lib/asyncio/windows_utils.py | |
parent | ef7f14036635e76f1bca975662130047d39314eb (diff) | |
parent | a9fa2664ab98a1077e5b16d66c17aea0cd631ed7 (diff) | |
download | cpython-b470f0dd2a4a539bb8ba44c818f685fb9a260d38.zip cpython-b470f0dd2a4a539bb8ba44c818f685fb9a260d38.tar.gz cpython-b470f0dd2a4a539bb8ba44c818f685fb9a260d38.tar.bz2 |
Merge 3.4: Issue #21119, fix ResourceWarning in asyncio
* Make sure that socketpair() close sockets on error. Close the listening
socket if sock.bind() raises an exception.
* asyncio now closes sockets on errors. Fix ResourceWarning:
create_connection(), create_datagram_endpoint() and create_unix_server()
methods of event loop now close the newly created socket on error.
Diffstat (limited to 'Lib/asyncio/windows_utils.py')
-rw-r--r-- | Lib/asyncio/windows_utils.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Lib/asyncio/windows_utils.py b/Lib/asyncio/windows_utils.py index 2a196cc..f7f2f35 100644 --- a/Lib/asyncio/windows_utils.py +++ b/Lib/asyncio/windows_utils.py @@ -51,23 +51,25 @@ def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): # We create a connected TCP socket. Note the trick with setblocking(0) # that prevents us from having to create a thread. lsock = socket.socket(family, type, proto) - lsock.bind((host, 0)) - lsock.listen(1) - # On IPv6, ignore flow_info and scope_id - addr, port = lsock.getsockname()[:2] - csock = socket.socket(family, type, proto) - csock.setblocking(False) try: - csock.connect((addr, port)) - except (BlockingIOError, InterruptedError): - pass - except Exception: + lsock.bind((host, 0)) + lsock.listen(1) + # On IPv6, ignore flow_info and scope_id + addr, port = lsock.getsockname()[:2] + csock = socket.socket(family, type, proto) + try: + csock.setblocking(False) + try: + csock.connect((addr, port)) + except (BlockingIOError, InterruptedError): + pass + ssock, _ = lsock.accept() + csock.setblocking(True) + except: + csock.close() + raise + finally: lsock.close() - csock.close() - raise - ssock, _ = lsock.accept() - csock.setblocking(True) - lsock.close() return (ssock, csock) |