Public: anyone can read this; the crew can change it.
Stopping production in the middle of a deploy reads "Not running", not "Failed to start" #16277
Check · Review · Land · Live done — Landed and live in production.
talk/fix-stop-is-not-a-failure → main 0 commits 2 threads · 2 unresolved
4 files
changed +33
−10
src/apps/runtime_deploy.ts +7 −4
| @@ -34,7 +34,7 @@ import type { AppManifest } from "./manifest.ts"; | ||
| 34 | 34 | import { heldManifest } from "../core/starts.ts"; |
| 35 | 35 | import { ASKS_NEXT, asksLine, heldPull } from "../checks/held.ts"; |
| 36 | 36 | import type { AppsRuntime } from "./runtime.ts"; |
| 37 | import { log, TESTS_PASSED_TAIL, NO_TESTS_TAIL, type Live, PUSH_REASONS, elapsedSeconds, type Environment, BUILD_PREVIEWS_MAX, key } from "./runtime_env.ts"; | |
| 37 | import { EnvStop, log, TESTS_PASSED_TAIL, NO_TESTS_TAIL, type Live, PUSH_REASONS, elapsedSeconds, type Environment, BUILD_PREVIEWS_MAX, key } from "./runtime_env.ts"; | |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Wait for an environment a request asked for to answer: until its deploy serves or ends, or |
| @@ -276,9 +276,12 @@ export async function execute( | ||
| 276 | 276 | // failure (a non-zero exit, a genuine timeout) still fails the run |
| 277 | 277 | // below even if the runtime happens to be stopping at the same time: |
| 278 | 278 | // only an abort this runtime raised earns the quieter outcome. |
| 279 | if (rt.stopped && abort.signal.aborted) { | |
| 280 | const done = cancelRun(rt.app.db, run.id, STOPPED_SUMMARY); | |
| 281 | write(`cancelled: ${STOPPED_SUMMARY}`); | |
| 279 | // So is a person stopping or removing this environment while it deployed (`EnvStop`): the run | |
| 280 | // is cancelled with what they did, so the environment reads stopped, not failed. | |
| 281 | const because = !abort.signal.aborted ? undefined : rt.stopped ? STOPPED_SUMMARY : abort.signal.reason instanceof EnvStop ? abort.signal.reason.summary : undefined; | |
| 282 | if (because !== undefined) { | |
| 283 | const done = cancelRun(rt.app.db, run.id, because); | |
| 284 | write(`cancelled: ${because}`); | |
| 282 | 285 | if (done) announceRun(rt.app, done); |
| 283 | 286 | return; |
| 284 | 287 | } |
src/apps/runtime_env.ts +9
| @@ -130,6 +130,15 @@ export const IDLE_PULL_DAYS = 3; | ||
| 130 | 130 | export const SWEEP_EVERY_MS = 60_000; |
| 131 | 131 | export const BUSY_GRACE_MS = 45 * 60_000; |
| 132 | 132 | |
| 133 | /** | |
| 134 | * Why a deploy in flight was aborted when a person stopped or removed its environment | |
| 135 | * (`runtime_teardown.ts`): the deploy's run is cancelled with `summary`, never failed, so a | |
| 136 | * production stopped mid-deploy reads "Not running", not "Failed to start". | |
| 137 | */ | |
| 138 | export class EnvStop { | |
| 139 | constructor(readonly summary: string) {} | |
| 140 | } | |
| 141 | ||
| 133 | 142 | /** What a finished deploy's summary ends with: the studio words its green |
| 134 | 143 | * from these, so a pull says whether its tests ran (`words.ts`). */ |
| 135 | 144 | export const TESTS_PASSED_TAIL = " · its tests passed"; |
src/apps/runtime_teardown.ts +3 −3
| @@ -9,7 +9,7 @@ import { revokeAppToken } from "./token.ts"; | ||
| 9 | 9 | import { cancelRun } from "../core/runs.ts"; |
| 10 | 10 | import { removeApp, removeEnv, type EnvName } from "./data.ts"; |
| 11 | 11 | import type { AppsRuntime } from "./runtime.ts"; |
| 12 | import { key } from "./runtime_env.ts"; | |
| 12 | import { EnvStop, key } from "./runtime_env.ts"; | |
| 13 | 13 | |
| 14 | 14 | export async function teardown(rt: AppsRuntime, record: AppRecord, env: EnvName): Promise<void> { |
| 15 | 15 | const k = key(record.id, env); |
| @@ -19,7 +19,7 @@ export async function teardown(rt: AppsRuntime, record: AppRecord, env: EnvName) | ||
| 19 | 19 | forgetLanded(rt.app, record.id, env); |
| 20 | 20 | if (state.queued) |
| 21 | 21 | cancelRun(rt.app.db, state.queued.id, "the environment was removed"); |
| 22 | state.deploying?.abort.abort(); | |
| 22 | state.deploying?.abort.abort(new EnvStop("the environment was removed")); | |
| 23 | 23 | await state.chain.catch(() => {}); |
| 24 | 24 | // Null the reference before stopping it: `watch()`'s exit handler |
| 25 | 25 | // only no-ops on a deliberate stop when `state.live` no longer points |
| @@ -58,7 +58,7 @@ export async function stopEnv(rt: AppsRuntime, record: AppRecord, env: EnvName): | ||
| 58 | 58 | const state = rt.envs.get(key(record.id, env)); |
| 59 | 59 | if (state === undefined) return; |
| 60 | 60 | if (state.queued) cancelRun(rt.app.db, state.queued.id, "stopped"); |
| 61 | state.deploying?.abort.abort(); | |
| 61 | state.deploying?.abort.abort(new EnvStop("stopped")); | |
| 62 | 62 | await state.chain.catch(() => {}); |
| 63 | 63 | const live = state.live; |
| 64 | 64 | state.live = undefined; |
test/web-apps.test.ts +14 −3
| @@ -1084,9 +1084,20 @@ describe("apps, runs and the crew on the web", () => { | ||
| 1084 | 1084 | }); |
| 1085 | 1085 | |
| 1086 | 1086 | test("the app page says in a sentence that production is not running, and what to do", async () => { |
| 1087 | // Production's environment is made by the first deploy: wait for its run. | |
| 1088 | await runsOf(hello, (r) => r.state !== "queued" && r.state !== "running", 30_000); | |
| 1089 | const stop = await web(alice, "/alice/hello/app/production/stop", { form: {} }); | |
| 1087 | // Stopped while a deploy is in flight, the case a loaded machine kept meeting: the deploy is | |
| 1088 | // held at the runtime's only permit, so it is claimed and waiting when the stop arrives. The | |
| 1089 | // stop waits for it, so the permit is given back only once the stop is under way. | |
| 1090 | const permit = await runtime.gate.acquire(); | |
| 1091 | let stopping: Promise<Response> | undefined; | |
| 1092 | try { | |
| 1093 | expect((await web(alice, "/alice/hello/app/production/redeploy", { form: {} })).status).toBe(303); | |
| 1094 | const [held] = await runsOf(hello, (r) => r.kind === "deploy" && r.reason === "redeploy" && r.state === "running", 30_000); | |
| 1095 | expect(held).toBeDefined(); | |
| 1096 | stopping = web(alice, "/alice/hello/app/production/stop", { form: {} }); | |
| 1097 | } finally { | |
| 1098 | permit(); | |
| 1099 | } | |
| 1100 | const stop = await stopping!; | |
| 1090 | 1101 | expect(stop.status).toBeLessThan(400); |
| 1091 | 1102 | try { |
| 1092 | 1103 | // /app is the app page's old address: it lands on the studio page. |
new above
offline
This block splits the doc comment above ("What a finished deploy's summary ends with") from
TESTS_PASSED_TAILbelow. MoveEnvStopso that comment stays attached to its constants.