diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index efe7f631..98ae9651 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -299,6 +299,11 @@ class DockerVM(BaseVM): """Stops this Docker container.""" try: + if self._telnet_server: + self._telnet_server.close() + yield from self._telnet_server.wait_closed() + self._telnet_server = None + if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running(): yield from self._ubridge_hypervisor.stop() @@ -306,10 +311,6 @@ class DockerVM(BaseVM): if state == "paused": yield from self.unpause() - if self._telnet_server: - self._telnet_server.close() - self._telnet_server = None - # t=5 number of seconds to wait before killing the container try: yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5}) diff --git a/gns3server/utils/asyncio/telnet_server.py b/gns3server/utils/asyncio/telnet_server.py index 1f7fabe2..72731ddd 100644 --- a/gns3server/utils/asyncio/telnet_server.py +++ b/gns3server/utils/asyncio/telnet_server.py @@ -125,13 +125,14 @@ class AsyncioTelnetServer: return_when=asyncio.FIRST_COMPLETED) for coro in done: data = coro.result() + + # Console is closed + if len(data) == 0: + raise ConnectionResetError() + if coro == network_read: network_read = asyncio.async(network_reader.read(READ_SIZE)) - # Remote console is closed - if len(data) == 0: - raise ConnectionResetError() - if IAC in data: data = yield from self._IAC_parser(data, network_reader, network_writer) if self._writer: diff --git a/tests/modules/docker/test_docker_vm.py b/tests/modules/docker/test_docker_vm.py index c049e572..d527fd55 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/modules/docker/test_docker_vm.py @@ -68,7 +68,6 @@ def test_start_command(vm): assert vm.start_command is None - def test_create(loop, project, manager): response = {