gh-117657: Fix file descriptor race in test_socket.py (#123697)

This commit is contained in:
Nadeshiko Manju 2024-09-07 03:00:28 +08:00 committed by GitHub
parent 5a4fb7ea1c
commit 8a46a2ec50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View File

@ -4806,15 +4806,13 @@ class InterruptedSendTimeoutTest(InterruptedTimeoutBase,
class TCPCloserTest(ThreadedTCPSocketTest): class TCPCloserTest(ThreadedTCPSocketTest):
def testClose(self): def testClose(self):
conn, addr = self.serv.accept() conn, _ = self.serv.accept()
conn.close()
sd = self.cli read, _, _ = select.select([conn], [], [], support.SHORT_TIMEOUT)
read, write, err = select.select([sd], [], [], 1.0) self.assertEqual(read, [conn])
self.assertEqual(read, [sd]) self.assertEqual(conn.recv(1), b'x')
self.assertEqual(sd.recv(1), b'') conn.close()
# Calling close() many times should be safe. # Calling close() many times should be safe.
conn.close() conn.close()
@ -4822,7 +4820,10 @@ class TCPCloserTest(ThreadedTCPSocketTest):
def _testClose(self): def _testClose(self):
self.cli.connect((HOST, self.port)) self.cli.connect((HOST, self.port))
time.sleep(1.0) self.cli.send(b'x')
read, _, _ = select.select([self.cli], [], [], support.SHORT_TIMEOUT)
self.assertEqual(read, [self.cli])
self.assertEqual(self.cli.recv(1), b'')
class BasicSocketPairTest(SocketPairTest): class BasicSocketPairTest(SocketPairTest):

View File

@ -15,8 +15,6 @@ race:set_allocator_unlocked
# These entries are for warnings that trigger in a library function, as called # These entries are for warnings that trigger in a library function, as called
# by a CPython function. # by a CPython function.
# https://gist.github.com/swtaarrs/8e0e365e1d9cecece3269a2fb2f2b8b8
race:sock_recv_impl
# https://gist.github.com/swtaarrs/08dfe7883b4c975c31ecb39388987a67 # https://gist.github.com/swtaarrs/08dfe7883b4c975c31ecb39388987a67
race:free_threadstate race:free_threadstate