From 2e71c4c25798295e6c4e58f382b961550f26ee71 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Mon, 12 Jul 2021 10:12:54 -0400 Subject: [PATCH] Fix a possible race condition in sslproto test 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. --- tests/test_tcp.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_tcp.py b/tests/test_tcp.py index 5b213d2c..dc79ba28 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -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): @@ -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() @@ -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))