mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
Merge pull request #2847 from yueguobin/fix/docker-pid1-signal-chain
fix: SIGKILL docker container on stop instead of 5s grace period
This commit is contained in:
commit
372874c7d5
@ -1049,11 +1049,14 @@ class DockerVM(BaseNode):
|
||||
|
||||
state = await self._get_container_state()
|
||||
if state != "stopped" and state != "exited":
|
||||
# t=5 number of seconds to wait before killing the container
|
||||
# SIGKILL immediately. GNS3 has already persisted container state
|
||||
# (permissions via _fix_permissions, /gns3volumes) before this
|
||||
# point, and the business process (often an interactive shell)
|
||||
# ignores SIGTERM — so a stop grace period buys nothing but latency.
|
||||
try:
|
||||
await self.manager.query("POST", f"containers/{self._cid}/stop", params={"t": 5})
|
||||
await self.manager.query("POST", f"containers/{self._cid}/kill")
|
||||
log.info(f"Docker container '{self._name}' [{self._image}] stopped")
|
||||
except DockerHttp304Error:
|
||||
except DockerHttp409Error:
|
||||
# Container is already stopped
|
||||
pass
|
||||
# Ignore runtime error because when closing the server
|
||||
|
||||
@ -1209,7 +1209,7 @@ async def test_stop(vm):
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||
vm._permissions_fixed = False
|
||||
await vm.stop()
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/kill")
|
||||
assert mock.stop.called
|
||||
assert vm._ubridge_hypervisor is None
|
||||
assert vm._fix_permissions.called
|
||||
@ -1222,7 +1222,7 @@ async def test_stop_paused_container(vm):
|
||||
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause") as mock_unpause:
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||
await vm.stop()
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
||||
mock_query.assert_called_with("POST", "containers/e90e34656842/kill")
|
||||
assert mock_unpause.called
|
||||
|
||||
|
||||
@ -1894,7 +1894,7 @@ async def test_stop_exited_container_no_stop_query(vm):
|
||||
vm._permissions_fixed = False
|
||||
await vm.stop()
|
||||
assert not any(
|
||||
call.args[:2] == ("POST", "containers/e90e34656842/stop")
|
||||
call.args[:2] == ("POST", "containers/e90e34656842/kill")
|
||||
for call in mock_query.mock_calls
|
||||
)
|
||||
assert vm.status == "stopped"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user