Commit 319c0345 authored by Julien Duponchelle's avatar Julien Duponchelle Committed by Yury Selivanov

bpo-29711: Fix stop_serving in proactor loop kill all listening servers (#431)

parent 36c2c044
...@@ -536,6 +536,8 @@ class BaseProactorEventLoop(base_events.BaseEventLoop): ...@@ -536,6 +536,8 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
self._accept_futures.clear() self._accept_futures.clear()
def _stop_serving(self, sock): def _stop_serving(self, sock):
self._stop_accept_futures() future = self._accept_futures.pop(sock.fileno(), None)
if future:
future.cancel()
self._proactor._stop_serving(sock) self._proactor._stop_serving(sock)
sock.close() sock.close()
...@@ -567,10 +567,21 @@ class BaseProactorEventLoopTests(test_utils.TestCase): ...@@ -567,10 +567,21 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
self.assertTrue(self.sock.close.called) self.assertTrue(self.sock.close.called)
def test_stop_serving(self): def test_stop_serving(self):
sock = mock.Mock() sock1 = mock.Mock()
self.loop._stop_serving(sock) future1 = mock.Mock()
self.assertTrue(sock.close.called) sock2 = mock.Mock()
self.proactor._stop_serving.assert_called_with(sock) future2 = mock.Mock()
self.loop._accept_futures = {
sock1.fileno(): future1,
sock2.fileno(): future2
}
self.loop._stop_serving(sock1)
self.assertTrue(sock1.close.called)
self.assertTrue(future1.cancel.called)
self.proactor._stop_serving.assert_called_with(sock1)
self.assertFalse(sock2.close.called)
self.assertFalse(future2.cancel.called)
if __name__ == '__main__': if __name__ == '__main__':
......
Fix ``stop_serving`` in asyncio proactor loop kill all listening servers
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment