Make container start idempotent (#792)

Fixes #772 

Today it fails in bootstrap the second go around, and we also have an
error handler that automatically cleans up the container if bootstrap
failed which is even worse. This change short circuits us first in the
cli if the state is running when we get() the container, and also adds
in a clause to bootstrap to just early return if we already have a
client.
This commit is contained in:
Danny Canter
2025-10-21 14:42:32 -07:00
committed by GitHub
parent b4814f0c4a
commit 2f507fe9d9
3 changed files with 63 additions and 1 deletions
@@ -215,6 +215,14 @@ public actor ContainersService {
do {
try await self.lock.withLock { context in
var state = try await self.getContainerState(id: id, context: context)
// We've already bootstrapped this container. Ideally we should be able to
// return some sort of error code from the sandbox svc to check here, but this
// is also a very simple check and faster than doing an rpc to get the same result.
if state.client != nil {
return
}
let runtime = state.snapshot.configuration.runtimeHandler
let sandboxClient = try await SandboxClient.create(
id: id,