From cebccf6f4123e38e6c6aabd4392be10dea02a8e5 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 3 Aug 2019 07:13:12 +0100 Subject: [PATCH] issue #549 / [stream-refactor]: fix close/poller deregister crash on OSX See source comment. --- mitogen/core.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index be5d7e9c..14fddc0f 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -1628,12 +1628,17 @@ class Protocol(object): self.stream.on_disconnect(broker) def on_disconnect(self, broker): + # Normally both sides an FD, so it is important that tranmit_side is + # deregistered from Poller before closing the receive side, as pollers + # like epoll and kqueue unregister all events on FD close, causing + # subsequent attempt to unregister the transmit side to fail. LOG.debug('%r: disconnecting', self) - if self.stream.receive_side: - broker.stop_receive(self.stream) - self.stream.receive_side.close() + broker.stop_receive(self.stream) if self.stream.transmit_side: broker._stop_transmit(self.stream) + + self.stream.receive_side.close() + if self.stream.transmit_side: self.stream.transmit_side.close()