Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix stop_serving in proactor loop kill all servers
Current implementation of the asyncio Proactor event loop has an
issue, when you stop a server it's cancel the futures of all other
servers.
  • Loading branch information
julien-duponchelle committed Nov 17, 2016
commit 857dd6aa5a88afc81d2a32728a57d2f768d9f65b
4 changes: 3 additions & 1 deletion asyncio/proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,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 tests/test_proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,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