From 58ff9b3ad8aa74c37b82a7a0d8a1076bb9dc22e0 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Thu, 5 Sep 2024 02:17:58 +0800 Subject: [PATCH 1/6] gh-123695: fix race:sock_recv_impl suppressions for free-thread building Signed-off-by: Manjusaka --- Lib/test/test_socket.py | 9 +++++---- Tools/tsan/suppressions_free_threading.txt | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 7c607a809aa428..c453723c7050e7 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4806,15 +4806,16 @@ def testInterruptedSendmsgTimeout(self): class TCPCloserTest(ThreadedTCPSocketTest): + def __init__(self, methodName='runTest'): + super().__init__(methodName) def testClose(self): conn, addr = self.serv.accept() - conn.close() sd = self.cli - read, write, err = select.select([sd], [], [], 1.0) - self.assertEqual(read, [sd]) - self.assertEqual(sd.recv(1), b'') + read, write, err = select.select([conn], [], [], 1.0) + self.assertEqual(read, [conn]) + self.assertEqual(conn.recv(1), b'') # Calling close() many times should be safe. conn.close() diff --git a/Tools/tsan/suppressions_free_threading.txt b/Tools/tsan/suppressions_free_threading.txt index 78449aed4009d3..e5eb665ae212de 100644 --- a/Tools/tsan/suppressions_free_threading.txt +++ b/Tools/tsan/suppressions_free_threading.txt @@ -15,8 +15,6 @@ race:set_allocator_unlocked # These entries are for warnings that trigger in a library function, as called # by a CPython function. -# https://gist.github.com/swtaarrs/8e0e365e1d9cecece3269a2fb2f2b8b8 -race:sock_recv_impl # https://gist.github.com/swtaarrs/08dfe7883b4c975c31ecb39388987a67 race:free_threadstate From 81361a0485d7f85bf20ab7d6ca61eaec5b3e02a3 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Thu, 5 Sep 2024 03:06:30 +0800 Subject: [PATCH 2/6] fix test failed Signed-off-by: Manjusaka --- Lib/test/test_socket.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index c453723c7050e7..c555d17bd48261 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4806,16 +4806,13 @@ def testInterruptedSendmsgTimeout(self): class TCPCloserTest(ThreadedTCPSocketTest): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def testClose(self): conn, addr = self.serv.accept() sd = self.cli read, write, err = select.select([conn], [], [], 1.0) self.assertEqual(read, [conn]) - self.assertEqual(conn.recv(1), b'') + self.assertEqual(conn.recv(1), b'x') # Calling close() many times should be safe. conn.close() @@ -4823,6 +4820,7 @@ def testClose(self): def _testClose(self): self.cli.connect((HOST, self.port)) + self.cli.send(b'x') time.sleep(1.0) From 756c584c54ffadfa7d443ad44d8645198a532ca2 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 7 Sep 2024 01:03:21 +0800 Subject: [PATCH 3/6] fix review idea Signed-off-by: Manjusaka --- Lib/test/test_socket.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index c555d17bd48261..0eafb55d624f54 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4814,6 +4814,8 @@ def testClose(self): self.assertEqual(read, [conn]) self.assertEqual(conn.recv(1), b'x') + conn.close() + # Calling close() many times should be safe. conn.close() conn.close() @@ -4822,6 +4824,9 @@ def _testClose(self): self.cli.connect((HOST, self.port)) self.cli.send(b'x') time.sleep(1.0) + read, write, _ = select.select([self.cli], [], [], 0.1) + self.assertEqual(read, [self.cli]) + self.assertEqual(self.cli.recv(1), b'') class BasicSocketPairTest(SocketPairTest): From c5b114b35357acdd4490851fcff9f93c6f8e7d71 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 7 Sep 2024 01:27:21 +0800 Subject: [PATCH 4/6] fix review idea Signed-off-by: Manjusaka --- Lib/test/test_socket.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 0eafb55d624f54..4a16467ffc406b 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4823,8 +4823,7 @@ def testClose(self): def _testClose(self): self.cli.connect((HOST, self.port)) self.cli.send(b'x') - time.sleep(1.0) - read, write, _ = select.select([self.cli], [], [], 0.1) + read, write, _ = select.select([self.cli], [], [], 1.0) self.assertEqual(read, [self.cli]) self.assertEqual(self.cli.recv(1), b'') From 4bfd9d94550eb1e7c11e5b54f80a1f60e141ecce Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 7 Sep 2024 01:29:11 +0800 Subject: [PATCH 5/6] fix review idea here Signed-off-by: Manjusaka --- Lib/test/test_socket.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 4a16467ffc406b..3365d371f044b9 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4807,13 +4807,11 @@ def testInterruptedSendmsgTimeout(self): class TCPCloserTest(ThreadedTCPSocketTest): def testClose(self): - conn, addr = self.serv.accept() + conn, _ = self.serv.accept() - sd = self.cli - read, write, err = select.select([conn], [], [], 1.0) + read, _, _ = select.select([conn], [], [], 1.0) self.assertEqual(read, [conn]) self.assertEqual(conn.recv(1), b'x') - conn.close() # Calling close() many times should be safe. @@ -4823,7 +4821,7 @@ def testClose(self): def _testClose(self): self.cli.connect((HOST, self.port)) self.cli.send(b'x') - read, write, _ = select.select([self.cli], [], [], 1.0) + read, _, _ = select.select([self.cli], [], [], 1.0) self.assertEqual(read, [self.cli]) self.assertEqual(self.cli.recv(1), b'') From 33ac4a37b0b90ddffaa60f78088152b94a987ace Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Sat, 7 Sep 2024 01:31:58 +0800 Subject: [PATCH 6/6] fix timeout setting Signed-off-by: Manjusaka --- Lib/test/test_socket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 3365d371f044b9..21c96820c41090 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4809,7 +4809,7 @@ class TCPCloserTest(ThreadedTCPSocketTest): def testClose(self): conn, _ = self.serv.accept() - read, _, _ = select.select([conn], [], [], 1.0) + read, _, _ = select.select([conn], [], [], support.SHORT_TIMEOUT) self.assertEqual(read, [conn]) self.assertEqual(conn.recv(1), b'x') conn.close() @@ -4821,7 +4821,7 @@ def testClose(self): def _testClose(self): self.cli.connect((HOST, self.port)) self.cli.send(b'x') - read, _, _ = select.select([self.cli], [], [], 1.0) + read, _, _ = select.select([self.cli], [], [], support.SHORT_TIMEOUT) self.assertEqual(read, [self.cli]) self.assertEqual(self.cli.recv(1), b'')