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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

talk/fix-stop-is-not-a-failure → main 0 commits 2 threads · 2 unresolved

  • Merged. talk/fix-stop-is-not-a-failure was merged into main as 14667cf.

Review

Sign in to review this change.
4 files changed +33 −10
src/apps/runtime_deploy.ts +7 −4
@@ -34,7 +34,7 @@ import type { AppManifest } from "./manifest.ts";
3434 import { heldManifest } from "../core/starts.ts";
3535 import { ASKS_NEXT, asksLine, heldPull } from "../checks/held.ts";
3636 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";
3838
3939 /**
4040 * 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(
276276 // failure (a non-zero exit, a genuine timeout) still fails the run
277277 // below even if the runtime happens to be stopping at the same time:
278278 // 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}`);
282285 if (done) announceRun(rt.app, done);
283286 return;
284287 }
src/apps/runtime_env.ts +9
@@ -130,6 +130,15 @@ export const IDLE_PULL_DAYS = 3;
130130 export const SWEEP_EVERY_MS = 60_000;
131131 export const BUSY_GRACE_MS = 45 * 60_000;
132132
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
outdated

This block splits the doc comment above ("What a finished deploy's summary ends with") from TESTS_PASSED_TAIL below. Move EnvStop so that comment stays attached to its constants.

136 * production stopped mid-deploy reads "Not running", not "Failed to start".
137 */
138 export class EnvStop {
139 constructor(readonly summary: string) {}
140 }
141
133142 /** What a finished deploy's summary ends with: the studio words its green
134143 * from these, so a pull says whether its tests ran (`words.ts`). */
135144 export const TESTS_PASSED_TAIL = " · its tests passed";
src/apps/runtime_teardown.ts +3 −3
@@ -9,7 +9,7 @@ import { revokeAppToken } from "./token.ts";
99 import { cancelRun } from "../core/runs.ts";
1010 import { removeApp, removeEnv, type EnvName } from "./data.ts";
1111 import type { AppsRuntime } from "./runtime.ts";
12 import { key } from "./runtime_env.ts";
12 import { EnvStop, key } from "./runtime_env.ts";
1313
1414 export async function teardown(rt: AppsRuntime, record: AppRecord, env: EnvName): Promise<void> {
1515 const k = key(record.id, env);
@@ -19,7 +19,7 @@ export async function teardown(rt: AppsRuntime, record: AppRecord, env: EnvName)
1919 forgetLanded(rt.app, record.id, env);
2020 if (state.queued)
2121 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"));
2323 await state.chain.catch(() => {});
2424 // Null the reference before stopping it: `watch()`'s exit handler
2525 // 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):
5858 const state = rt.envs.get(key(record.id, env));
5959 if (state === undefined) return;
6060 if (state.queued) cancelRun(rt.app.db, state.queued.id, "stopped");
61 state.deploying?.abort.abort();
61 state.deploying?.abort.abort(new EnvStop("stopped"));
6262 await state.chain.catch(() => {});
6363 const live = state.live;
6464 state.live = undefined;
test/web-apps.test.ts +14 −3
@@ -1084,9 +1084,20 @@ describe("apps, runs and the crew on the web", () => {
10841084 });
10851085
10861086 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!;
10901101 expect(stop.status).toBeLessThan(400);
10911102 try {
10921103 // /app is the app page's old address: it lands on the studio page.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs