mirror of
https://github.com/apple/container.git
synced 2026-09-28 01:46:25 -04:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user