Skip to content

Commit

Permalink
bpo-29711: Fix stop_serving in proactor loop kill all listening serve…
Browse files Browse the repository at this point in the history
…rs (#431)
  • Loading branch information
julien-duponchelle authored and 1st1 committed Dec 19, 2017
1 parent 36c2c04 commit 319c034
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Lib/asyncio/proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ def _stop_accept_futures(self):
self._accept_futures.clear()

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)
sock.close()
19 changes: 15 additions & 4 deletions Lib/test/test_asyncio/test_proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,21 @@ def test_create_server_cancel(self):
self.assertTrue(self.sock.close.called)

def test_stop_serving(self):
sock = mock.Mock()
self.loop._stop_serving(sock)
self.assertTrue(sock.close.called)
self.proactor._stop_serving.assert_called_with(sock)
sock1 = mock.Mock()
future1 = mock.Mock()
sock2 = mock.Mock()
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__':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``stop_serving`` in asyncio proactor loop kill all listening servers

0 comments on commit 319c034

Please sign in to comment.