[3.11] GH-100573: Fix server hang caused by os.stat() on named pipe (Windows) (GH-100959) (#101019)

(cherry picked from commit 1bc7a73683)
This commit is contained in:
Miss Islington (bot) 2023-01-13 13:58:20 -08:00 committed by GitHub
parent 6492492ce7
commit d06315a6fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View file

@ -250,6 +250,46 @@ class ProactorTests(test_utils.TestCase):
proactor.sendto(sock, b'abc', addr=bad_address)
sock.close()
def test_client_pipe_stat(self):
res = self.loop.run_until_complete(self._test_client_pipe_stat())
self.assertEqual(res, 'done')
async def _test_client_pipe_stat(self):
# Regression test for https://github.com/python/cpython/issues/100573
ADDRESS = r'\\.\pipe\test_client_pipe_stat-%s' % os.getpid()
async def probe():
# See https://github.com/python/cpython/pull/100959#discussion_r1068533658
h = _overlapped.ConnectPipe(ADDRESS)
try:
_winapi.CloseHandle(_overlapped.ConnectPipe(ADDRESS))
except OSError as e:
if e.winerror != _overlapped.ERROR_PIPE_BUSY:
raise
finally:
_winapi.CloseHandle(h)
with self.assertRaises(FileNotFoundError):
await probe()
[server] = await self.loop.start_serving_pipe(asyncio.Protocol, ADDRESS)
self.assertIsInstance(server, windows_events.PipeServer)
errors = []
self.loop.set_exception_handler(lambda _, data: errors.append(data))
for i in range(5):
await self.loop.create_task(probe())
self.assertEqual(len(errors), 0, errors)
server.close()
with self.assertRaises(FileNotFoundError):
await probe()
return "done"
class WinPolicyTests(test_utils.TestCase):