Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pm-stack/console/edge/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ async function serving() {
}

let address = null;
/** What the last health request heard, for the line that says a wait failed. */
let heard = "nothing asked yet";
async function health() {
if (!address && process.env.PM_RELEASE_HEALTH) address = `${process.env.PM_RELEASE_HEALTH}/${worker}`;
if (!address) {
Expand All @@ -131,10 +133,23 @@ async function health() {
if (status !== 200 || typeof sub !== "string") throw new Error("cannot read the account's workers.dev subdomain");
address = `https://${worker}.${sub}.workers.dev/console/health`;
}
// What came back that was not a health answer is kept, in a line, so
// that a Worker that did not answer is not just "silent": an error
// page, a refusal and no route to it are different faults.
let res;
try {
const res = await fetch(address, { signal: AbortSignal.timeout(10_000), headers: { "cache-control": "no-cache" } });
return await res.json();
res = await fetch(address, { signal: AbortSignal.timeout(10_000), headers: { "cache-control": "no-cache" } });
} catch (error) {
heard = `no answer (${error.name}: ${String(error.cause?.code ?? error.cause?.message ?? error.message).slice(0, 80)})`;
return null;
}
const text = await res.text().catch(() => "");
try {
const answer = JSON.parse(text);
heard = `http ${res.status}, ${text.slice(0, 160)}`;
return answer;
} catch {
heard = `http ${res.status} ${res.headers.get("content-type") ?? "of no type"}: ${text.replace(/\s+/g, " ").slice(0, 160)}`;
return null;
}
}
Expand All @@ -147,7 +162,7 @@ async function answers(want) {
if (last === want) return true;
await sleep(HEALTH_WAIT_MS);
}
say(`${worker} did not answer as ${want === "this" ? commit.short : want} (last answer: ${last})`);
say(`${worker} did not answer as ${want === "this" ? commit.short : want} (last answer: ${last}; it said: ${heard})`);
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions pm-stack/console/test/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ process.exit(status);
// What was serving before is serving again.
expect(serving(REAL)).toEqual({ kind: "app", short: "aaaaaaaaaaaa" });
expect(got.err).toContain(`${REAL} is not serving ${SHORT}`);
// And the run says what it heard in place of a health answer: an
// error page is a different fault from no route, and "silent" alone
// told them apart for nobody.
expect(got.out + got.err).toContain("(last answer: silent; it said: http 500 ");
expect(got.out + got.err).toContain("error code: 1101");
});

test("an upload that fails changes nothing that is serving", async () => {
Expand Down