1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

Avoid consuming 100% of CPU when stopping docker container

Fix #427
This commit is contained in:
Julien Duponchelle 2016-02-19 17:53:17 +01:00
parent f4f9e6eba6
commit f35c742b07
No known key found for this signature in database
GPG Key ID: F1E2485547D4595D
3 changed files with 10 additions and 9 deletions

View File

@ -299,6 +299,11 @@ class DockerVM(BaseVM):
"""Stops this Docker container.""" """Stops this Docker container."""
try: 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(): if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
yield from self._ubridge_hypervisor.stop() yield from self._ubridge_hypervisor.stop()
@ -306,10 +311,6 @@ class DockerVM(BaseVM):
if state == "paused": if state == "paused":
yield from self.unpause() 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 # t=5 number of seconds to wait before killing the container
try: try:
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5}) yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})

View File

@ -125,13 +125,14 @@ class AsyncioTelnetServer:
return_when=asyncio.FIRST_COMPLETED) return_when=asyncio.FIRST_COMPLETED)
for coro in done: for coro in done:
data = coro.result() data = coro.result()
if coro == network_read:
network_read = asyncio.async(network_reader.read(READ_SIZE))
# Remote console is closed # Console is closed
if len(data) == 0: if len(data) == 0:
raise ConnectionResetError() raise ConnectionResetError()
if coro == network_read:
network_read = asyncio.async(network_reader.read(READ_SIZE))
if IAC in data: if IAC in data:
data = yield from self._IAC_parser(data, network_reader, network_writer) data = yield from self._IAC_parser(data, network_reader, network_writer)
if self._writer: if self._writer:

View File

@ -68,7 +68,6 @@ def test_start_command(vm):
assert vm.start_command is None assert vm.start_command is None
def test_create(loop, project, manager): def test_create(loop, project, manager):
response = { response = {