diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-01-26 10:02:18 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-01-26 10:02:18 (GMT) |
commit | 2596dd08949f530c97bb6a2eda506594840d9726 (patch) | |
tree | 51bc5ec700e6fbd726545bfb6ec132364732f61e | |
parent | 21d7533c4c13489b4b3baae59f9e25cd038fb16b (diff) | |
download | cpython-2596dd08949f530c97bb6a2eda506594840d9726.zip cpython-2596dd08949f530c97bb6a2eda506594840d9726.tar.gz cpython-2596dd08949f530c97bb6a2eda506594840d9726.tar.bz2 |
asyncio: Close transports on error
Fix create_datagram_endpoint(), connect_read_pipe() and connect_write_pipe():
close the transport if the task is cancelled or on error.
-rw-r--r-- | Lib/asyncio/base_events.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 1ceeb2d..e43441e 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -723,7 +723,13 @@ class BaseEventLoop(events.AbstractEventLoop): logger.debug("Datagram endpoint remote_addr=%r created: " "(%r, %r)", remote_addr, transport, protocol) - yield from waiter + + try: + yield from waiter + except: + transport.close() + raise + return transport, protocol @coroutine @@ -815,7 +821,13 @@ class BaseEventLoop(events.AbstractEventLoop): protocol = protocol_factory() waiter = futures.Future(loop=self) transport = self._make_read_pipe_transport(pipe, protocol, waiter) - yield from waiter + + try: + yield from waiter + except: + transport.close() + raise + if self._debug: logger.debug('Read pipe %r connected: (%r, %r)', pipe.fileno(), transport, protocol) @@ -826,7 +838,13 @@ class BaseEventLoop(events.AbstractEventLoop): protocol = protocol_factory() waiter = futures.Future(loop=self) transport = self._make_write_pipe_transport(pipe, protocol, waiter) - yield from waiter + + try: + yield from waiter + except: + transport.close() + raise + if self._debug: logger.debug('Write pipe %r connected: (%r, %r)', pipe.fileno(), transport, protocol) |