Fix: Improve Docker container deletion error logging

When closing a Docker node, if container deletion fails, the error
is silently ignored. This can lead to stale containers remaining on
the system and causing 409 conflicts when reopening projects.

Changes:
- Distinguish between 404 (container already removed, normal) and
  other DockerError (deletion failed, needs attention)
- Log warning when deletion fails with error details
- Add comment explaining stale containers will be cleaned up on
  project open (via automatic 409 conflict resolution)

This improves observability without blocking project close operations.
The root cause of stale containers can now be diagnosed from logs.

Fixes #2708

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
YueGuobin 2026-05-07 12:45:05 +08:00
parent 3928377f80
commit 822abbe671
No known key found for this signature in database

View File

@ -1089,8 +1089,13 @@ class DockerVM(BaseNode):
# force - 1/True/true or 0/False/false, Kill then remove the container. Default false.
try:
await self.manager.query("DELETE", f"containers/{self._cid}", params={"force": 1, "v": 1})
except DockerError:
except DockerHttp404Error:
# Container already removed (normal case)
pass
except DockerError as e:
# Container deletion failed - log warning but don't block project close
# The stale container will be cleaned up when the project is opened again
log.warning(f"Failed to delete Docker container '{self.docker_name}': {e}")
log.info("Docker container '{name}' [{image}] removed".format(name=self._name, image=self._image))
if release_nio_udp_ports: