fix: SIGKILL docker container on stop instead of 5s grace period

Docker node stop took ~5s every time. The stop API grace period
(params t=5, unchanged since 2015) was always exhausted: the business
process (often an interactive shell) ignores SIGTERM, and GNS3 doesn't
depend on graceful shutdown — _fix_permissions and /gns3volumes already
persist container state before stop() is called.

Use POST /containers/{id}/kill (SIGKILL, zero delay) instead of stop.
The 409 (container already stopped) replaces the previous 304 handling
for the race where the container exits between the state check and the call.

t=5 traced to commit 33edbefa3 (2015-10-14) "Docker cleanup and
improvements" — introduced with no recorded rationale.
This commit is contained in:
YueGuobin committed 2026-08-10 21:48:26 +08:00
1 parent cf072c7922
commit e7dfe9c7c4
2 files changed
+9 -6

No files matched your search

+6 -3
View File
@@ -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