]> granicus.if.org Git - python/commitdiff
asyncio: Close transports on error
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 26 Jan 2015 10:02:18 +0000 (11:02 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 26 Jan 2015 10:02:18 +0000 (11:02 +0100)
Fix create_datagram_endpoint(), connect_read_pipe() and connect_write_pipe():
close the transport if the task is cancelled or on error.

Lib/asyncio/base_events.py

index 1ceeb2d29552783b565f9e2d59e3a7d526b562b6..e43441ea2dd1ed6e3b46ec2cfab33d4139e174b8 100644 (file)
@@ -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)