diff --git a/pm-stack/console/edge/release.mjs b/pm-stack/console/edge/release.mjs index f4425a416a..05b0faf787 100644 --- a/pm-stack/console/edge/release.mjs +++ b/pm-stack/console/edge/release.mjs @@ -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) { @@ -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; } } @@ -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; } diff --git a/pm-stack/console/test/release.test.ts b/pm-stack/console/test/release.test.ts index eadf42fbdf..3c3561e2aa 100644 --- a/pm-stack/console/test/release.test.ts +++ b/pm-stack/console/test/release.test.ts @@ -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 () => {