summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/windows_utils.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-03 22:12:28 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-03 22:12:28 (GMT)
commita9fa2664ab98a1077e5b16d66c17aea0cd631ed7 (patch)
tree6a7b983b052c0faeaccd9dedc2d644959aadd6fc /Lib/asyncio/windows_utils.py
parent223a624158254e2c907116a756f6ffe63c49fb7a (diff)
downloadcpython-a9fa2664ab98a1077e5b16d66c17aea0cd631ed7.zip
cpython-a9fa2664ab98a1077e5b16d66c17aea0cd631ed7.tar.gz
cpython-a9fa2664ab98a1077e5b16d66c17aea0cd631ed7.tar.bz2
Issue #21119: asyncio: Make sure that socketpair() close sockets on error
Close the listening socket if sock.bind() raises an exception.
Diffstat (limited to 'Lib/asyncio/windows_utils.py')
-rw-r--r--Lib/asyncio/windows_utils.py32
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)