Repository navigation
Description
Summary
tale restore decides which containers are live with two different tests. A colour replica (backend-api, backend-worker, platform in <id>-blue / <id>-green) whose Docker state is restarting or paused counts as not running, so tale restore neither refuses because of it nor stops it with --stop. Under the unless-stopped restart policy such a replica keeps trying to start while the snapshot is written into the volumes.
Anchors are at main 009f64d141.
What the code does today
restore.ts:75-102findRunningProjectContainershas two branches:- the stateful tier and the dev stack, by their pinned names, through
isContainerRunning; - both colours, by their compose project, through
listComposeContainers, keeping onlycontainer.running.
- the stateful tier and the dev stack, by their pinned names, through
is-container-running.ts:3-14reads{{.State.Running}}, which Docker sets forrunning,restartingandpausedalike.list-service-containers.ts:72-96reads thedocker ps -afield{{.State}}and setsrunning: state === 'running', sorestartingandpausedarefalse.restore.ts:177-192refuses without--stop, or stops each listed name with--stop, only for the names that function returned. The comment above it states the reason: "Restoring under a live stack guarantees corruption".- Colour services run with
restart: 'unless-stopped'(create-backend-services.ts:80,create-platform-service.ts:25). A replica that exits with an error is restarted by Docker with backoff, and between attempts its state isrestarting.
Observed
On Docker 29.6.1 (Docker Desktop, macOS), a stand-in container ran with --restart unless-stopped, the labels com.docker.compose.project=standin-blue and com.docker.compose.service=backend-api, and the command sh -c 'sleep 1; exit 1'. Polled every 0.5 s:
| Sample | docker ps -a {{.State}} (what listComposeContainers reads) |
inspect {{.State.Running}}/{{.State.Restarting}} (what isContainerRunning reads) |
|---|---|---|
| t=1 | running |
true/false |
| t=7 | restarting |
true/true |
The same container is "running" for one helper and not for the other while it waits to restart.
Not examined
- A full
tale restore --stopagainst a workspace with a crash-looping colour replica was not run. - So the following consequence is derived from the code above, not observed. When the database comes back, for example through the
tale deploy --stopthat the restore suggests atrestore.ts:301-308, the surviving replica's next start runs its boot migrations against the restored data. - After the automation writer protocol cutover (fix(cli): let tale deploy cross the automation protocol cutover #4954) this matters more. A protocol-2 replica that survives the restore of a pre-cutover snapshot would apply migration
0163to it without the cutover barrier, and would put that snapshot's unfinished automation runs on hold. pausedwas not exercised with the stand-in. The claim about it rests on Docker's state model (State.Runningis true while paused).
Constraints any change must respect
- A restore must never write into the volumes while any process that can reach them may start.
- Without
--stop, a restore refuses and changes nothing. With--stop, it stops what it found and aborts if a stop fails (restore.ts:186-191). docker stopon arestartingcontainer ends the restart loop.unless-stoppedthen keeps it down, including across a daemon restart.- The two helpers have other callers:
listComposeContainers(with its running-only wrapperlistRunningServiceContainers,list-service-containers.ts:114-122) also servescolor-lifecycle.ts,logs.tsandreset.ts, andisContainerRunningserves more than restore; a change to their meaning reaches those callers too.
Options (no preference)
- One predicate for restore. Treat every state except
exited,createdanddeadas live for both branches, so the refusal and--stopsee the same set. - Stop the colour projects as a whole. Stop or refuse on every container of
<id>-blueand<id>-greenwhatever its state, for exampledocker compose -p <id>-<colour> stop. - Remove the colour containers before restoring. The restore already asks for a redeploy afterwards, but this drops the previous colour that
tale rollbackwould use. - Name the state in the refusal (for example "
<name>is restarting") and keep the stop list as is. This informs the operator but does not close the window.
Questions
- Should
pausedcount as live for a restore? A paused process holds its connections but cannot act until it is unpaused. - Should the same predicate apply to the stateful tier's pinned names, which already count
restartingthroughState.Running? - Should a restore that finds a replica of a newer release than the snapshot refuse outright, whatever its state?
Related
- fix(cli): let tale deploy cross the automation protocol cutover #4954, where this surfaced while reviewing the cutover's recovery paths.
- Backups and restore.
Activity
fix(cli): refuse or stop restarting and paused replicas on restore