asyncio icon indicating copy to clipboard operation
asyncio copied to clipboard

race condition in closing server returned by Proactor start_serving_pipe

Open sbourdeauducq opened this issue 9 years ago • 1 comments

The following program intermittently gets a invalid handle error from self.server[0].close().

from functools import partial
import asyncio


loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)


class Bug:
    def _child_connected(self, reader, writer):
        self.server[0].close()
        print("connected, closing server")

    async def start(self):
        def factory():
            reader = asyncio.StreamReader(loop=loop)
            protocol = asyncio.StreamReaderProtocol(reader,
                                            self._child_connected,
                                            loop=loop)
            return protocol
        self.server = await loop.start_serving_pipe(
            factory, "\\\\.\\pipe\\totoalecole1234")

bug = Bug()
loop.run_until_complete(bug.start())
loop.run_forever()

sbourdeauducq avatar Feb 19 '16 17:02 sbourdeauducq

Can you write a unittest that reproduces the problem?

1st1 avatar Mar 02 '16 16:03 1st1