Skip to content

Commit

Permalink
Fix a possible race condition in sslproto test
Browse files Browse the repository at this point in the history
test_shutdown_timeout_handler_not_set() might have a race between the
SHUT_WR message and `eof` asyncio event. This fix changes to use the
eof_received() callback triggered by SHUT_WR. Refs #412 2nd issue.
  • Loading branch information
fantix committed Jul 13, 2021
1 parent 0df1228 commit 2e71c4c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tests/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2870,8 +2870,11 @@ async def client(addr, ctx):
self.assertIsNone(ctx())

def test_shutdown_timeout_handler_not_set(self):
if self.implementation == 'asyncio':
# asyncio doesn't call SSL eof_received() so we can't run this test
raise unittest.SkipTest()

loop = self.loop
eof = asyncio.Event()
extra = None

def server(sock):
Expand All @@ -2883,7 +2886,6 @@ def server(sock):
sock.send(b'extra bytes')
# sending EOF here
sock.shutdown(socket.SHUT_WR)
loop.call_soon_threadsafe(eof.set)
# make sure we have enough time to reproduce the issue
self.assertEqual(sock.recv(1024), b'')
sock.close()
Expand Down Expand Up @@ -2911,17 +2913,16 @@ def connection_lost(self, exc):
else:
self.fut.set_exception(exc)

def eof_received(self):
self.transport.resume_reading()

async def client(addr):
ctx = self._create_client_ssl_context()
tr, pr = await loop.create_connection(Protocol, *addr, ssl=ctx)
await eof.wait()
tr.resume_reading()
await pr.fut
tr.close()
if self.implementation != 'asyncio':
# extra data received after transport.close() should be
# ignored - this is likely a bug in asyncio
self.assertIsNone(extra)
# extra data received after transport.close() should be ignored
self.assertIsNone(extra)

with self.tcp_server(server) as srv:
loop.run_until_complete(client(srv.addr))
Expand Down

0 comments on commit 2e71c4c

Please sign in to comment.