From 5f5427f51f20e5abf402b059cd464a7327c632a1 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 19 Feb 2016 17:39:30 +0100 Subject: [PATCH] protocols/pipe_ipc: work around race condition with loop.start_serving_pipe/close on Windows --- artiq/protocols/pipe_ipc.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/artiq/protocols/pipe_ipc.py b/artiq/protocols/pipe_ipc.py index c44ca7be3..4ac416a09 100644 --- a/artiq/protocols/pipe_ipc.py +++ b/artiq/protocols/pipe_ipc.py @@ -141,7 +141,16 @@ else: # windows asyncio.ensure_future(self._autoclose()) def _child_connected(self, reader, writer): - self.server[0].close() + # HACK: We should shut down the pipe server here. + # However, self.server[0].close() is racy, and will cause an + # invalid handle error if loop.start_serving_pipe has not finished + # its work in the background. + # The bug manifests itself here frequently as the event loop is + # reopening the server as soon as a new client connects. + # There is still a race condition in the AsyncioParentComm + # creation/destruction, but it is unlikely to cause problems + # in most practical cases. + assert self.server is not None self.server = None self.reader = reader self.writer = writer