Skip to content

Commit

Permalink
bpo-35602: Make sure the transport is always closed in SelectorEventL…
Browse files Browse the repository at this point in the history
…oopUnixSockSendfileTests (GH-11338)

There is a race condition in SelectorEventLoopUnixSockSendfileTests that causes the prepare() method return a non connected server protocol, making the cleanup() method skips the correct handling of the transport. This commit makes prepare() always return a connected server protocol that can always be cleaned up correctly.
  • Loading branch information
pablogsal committed Dec 29, 2018
1 parent 78de011 commit d51324a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Lib/test/test_asyncio/test_unix_events.py
Expand Up @@ -449,10 +449,12 @@ def __init__(self, loop):
self.data = bytearray()
self.fut = loop.create_future()
self.transport = None
self._ready = loop.create_future()

def connection_made(self, transport):
self.started = True
self.transport = transport
self._ready.set_result(None)

def data_received(self, data):
self.data.extend(data)
Expand Down Expand Up @@ -503,13 +505,11 @@ def prepare(self):
server = self.run_loop(self.loop.create_server(
lambda: proto, sock=srv_sock))
self.run_loop(self.loop.sock_connect(sock, (support.HOST, port)))
self.run_loop(proto._ready)

def cleanup():
if proto.transport is not None:
# can be None if the task was cancelled before
# connection_made callback
proto.transport.close()
self.run_loop(proto.wait_closed())
proto.transport.close()
self.run_loop(proto.wait_closed())

server.close()
self.run_loop(server.wait_closed())
Expand Down

0 comments on commit d51324a

Please sign in to comment.