Skip to content

Commit b0526cd

Browse files
committed
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.
1 parent 2081db8 commit b0526cd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

tests/test_tcp.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -2870,8 +2870,11 @@ async def client(addr, ctx):
28702870
self.assertIsNone(ctx())
28712871

28722872
def test_shutdown_timeout_handler_not_set(self):
2873+
if self.implementation == 'asyncio':
2874+
# asyncio doesn't call SSL eof_received() so we can't run this test
2875+
raise unittest.SkipTest()
2876+
28732877
loop = self.loop
2874-
eof = asyncio.Event()
28752878
extra = None
28762879

28772880
def server(sock):
@@ -2883,7 +2886,6 @@ def server(sock):
28832886
sock.send(b'extra bytes')
28842887
# sending EOF here
28852888
sock.shutdown(socket.SHUT_WR)
2886-
loop.call_soon_threadsafe(eof.set)
28872889
# make sure we have enough time to reproduce the issue
28882890
self.assertEqual(sock.recv(1024), b'')
28892891
sock.close()
@@ -2911,17 +2913,16 @@ def connection_lost(self, exc):
29112913
else:
29122914
self.fut.set_exception(exc)
29132915

2916+
def eof_received(self):
2917+
self.transport.resume_reading()
2918+
29142919
async def client(addr):
29152920
ctx = self._create_client_ssl_context()
29162921
tr, pr = await loop.create_connection(Protocol, *addr, ssl=ctx)
2917-
await eof.wait()
2918-
tr.resume_reading()
29192922
await pr.fut
29202923
tr.close()
2921-
if self.implementation != 'asyncio':
2922-
# extra data received after transport.close() should be
2923-
# ignored - this is likely a bug in asyncio
2924-
self.assertIsNone(extra)
2924+
# extra data received after transport.close() should be ignored
2925+
self.assertIsNone(extra)
29252926

29262927
with self.tcp_server(server) as srv:
29272928
loop.run_until_complete(client(srv.addr))

0 commit comments

Comments
 (0)