fix: remove container even if already removed

This commit is contained in:
2025-09-25 15:28:35 -06:00
parent 407c1a1c9b
commit a66843714d

View File

@@ -915,8 +915,21 @@ class ContainerManager:
self.session_manager.remove_session(session.id) self.session_manager.remove_session(session.id)
return True return True
except DockerException as e: except DockerException as e:
print(f"Error closing session {session.id}: {e}") error_message = str(e).lower()
return False # If container is not running or already removed, still remove it from session list
if (
"is not running" in error_message
or "no such container" in error_message
or "not found" in error_message
):
print(
f"Container already stopped/removed, removing session {session.id} from list"
)
self.session_manager.remove_session(session.id)
return True
else:
print(f"Error closing session {session.id}: {e}")
return False
def close_all_sessions( def close_all_sessions(
self, progress_callback=None, kill: bool = False self, progress_callback=None, kill: bool = False
@@ -980,11 +993,30 @@ class ContainerManager:
return True return True
except DockerException as e: except DockerException as e:
error_msg = f"Error: {str(e)}" error_message = str(e).lower()
if progress_callback: # If container is not running or already removed, still remove it from session list
progress_callback(session.id, "failed", error_msg) if (
print(f"Error closing session {session.id}: {e}") "is not running" in error_message
return False or "no such container" in error_message
or "not found" in error_message
):
print(
f"Container already stopped/removed, removing session {session.id} from list"
)
self.session_manager.remove_session(session.id)
if progress_callback:
progress_callback(
session.id,
"completed",
f"{session.name} removed from list (container already stopped)",
)
return True
else:
error_msg = f"Error: {str(e)}"
if progress_callback:
progress_callback(session.id, "failed", error_msg)
print(f"Error closing session {session.id}: {e}")
return False
# Use ThreadPoolExecutor to close sessions in parallel # Use ThreadPoolExecutor to close sessions in parallel
with concurrent.futures.ThreadPoolExecutor( with concurrent.futures.ThreadPoolExecutor(