diff --git a/plugins/team-setup/app.tsx b/plugins/team-setup/app.tsx
index e777d188..05c91f20 100644
--- a/plugins/team-setup/app.tsx
+++ b/plugins/team-setup/app.tsx
@@ -492,11 +492,11 @@ function ServerUpdateBanner() {
{restarting ? (
- Restarting your server. This page reloads when it is back, in about a minute.
+ Restarting your server. This page reloads in a moment and comes back when it is up.
) : (
- A new build of your bb server is ready. Restarting takes about a minute and interrupts any running turn; if you never
- do, it restarts tonight.
+ A new build of your bb server is ready. Restarting takes under a minute and interrupts any running turn; if you
+ never do, it restarts tonight.
)}
diff --git a/plugins/team-setup/server-update.test.ts b/plugins/team-setup/server-update.test.ts
index 641c312b..f57781f4 100644
--- a/plugins/team-setup/server-update.test.ts
+++ b/plugins/team-setup/server-update.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { createUpdateStore, POLL_MS, RESTART_POLL_MS, UPDATE_PATH, type UpdateStoreDeps } from "./server-update.js";
+import { createUpdateStore, POLL_MS, RESTART_POLL_MS, RESTART_TIMEOUT_MS, UPDATE_PATH, type UpdateStoreDeps } from "./server-update.js";
// A router and a clock the test drives. Timers fire only when `advance` is
// called, so each step is explicit.
@@ -98,14 +98,13 @@ describe("update store", () => {
expect(store.getState()).toEqual({ status: "pending" });
});
- it("applies, follows the restart down and up, then reloads", async () => {
+ it("applies, then reloads as soon as the server has gone down", async () => {
const h = harness([
{ status: 200, body: { pending: true, ready: true } },
{ status: 200, body: { applied: true } },
{ status: 200, body: { pending: false, ready: true } }, // old pod still up
{ status: 503 }, // router briefly away
{ status: 200, body: { pending: false, ready: false } },
- { status: 200, body: { pending: false, ready: true } },
]);
const store = createUpdateStore(h.deps);
store.subscribe(() => {});
@@ -115,10 +114,43 @@ describe("update store", () => {
await h.flush();
expect(store.getState()).toEqual({ status: "restarting" });
expect(h.calls[1]).toEqual({ method: "POST" });
- for (let i = 0; i < 4; i++) await h.advance(RESTART_POLL_MS);
+ for (let i = 0; i < 2; i++) await h.advance(RESTART_POLL_MS);
+ expect(h.reloaded()).toBe(0);
+ await h.advance(RESTART_POLL_MS);
+ await applied;
+ expect(h.reloaded()).toBe(1);
+ expect(h.calls).toHaveLength(5);
+ });
+
+ it("reloads anyway when the server never reports going down", async () => {
+ const answers: Array<{ status: number; body?: unknown }> = [
+ { status: 200, body: { pending: true, ready: true } },
+ { status: 200, body: { applied: true } },
+ ];
+ for (let i = 0; i < 100; i++) answers.push({ status: 200, body: { pending: false, ready: true } });
+ const h = harness(answers);
+ const store = createUpdateStore(h.deps);
+ store.subscribe(() => {});
+ await h.flush();
+ const applied = store.apply();
+ await h.flush();
+ for (let i = 0; i * RESTART_POLL_MS < RESTART_TIMEOUT_MS; i++) await h.advance(RESTART_POLL_MS);
await applied;
expect(h.reloaded()).toBe(1);
- expect(h.calls).toHaveLength(6);
+ });
+
+ it("drops the banner without reloading when there was nothing to apply", async () => {
+ const h = harness([
+ { status: 200, body: { pending: true, ready: true } },
+ { status: 200, body: { applied: false } },
+ ]);
+ const store = createUpdateStore(h.deps);
+ store.subscribe(() => {});
+ await h.flush();
+ await store.apply();
+ expect(store.getState()).toEqual({ status: "current" });
+ expect(h.reloaded()).toBe(0);
+ expect(h.timers).toHaveLength(1); // only the regular poll
});
it("reports a refused apply instead of waiting forever", async () => {
diff --git a/plugins/team-setup/server-update.ts b/plugins/team-setup/server-update.ts
index 845b3e27..ce046c43 100644
--- a/plugins/team-setup/server-update.ts
+++ b/plugins/team-setup/server-update.ts
@@ -13,10 +13,10 @@
export const UPDATE_PATH = "/_bb-gate/update";
export const POLL_MS = 60_000;
-export const RESTART_POLL_MS = 3_000;
-// A restart that has not come back by then is not one the banner can
-// explain; reload and let the gate's starting page take over.
-export const RESTART_TIMEOUT_MS = 4 * 60_000;
+export const RESTART_POLL_MS = 500;
+// A restart the Deployment has not reported within this long is not one the
+// banner can explain; reload anyway and let the gate sort it out.
+export const RESTART_TIMEOUT_MS = 15_000;
export type UpdateState =
| { status: "unknown" }
@@ -24,8 +24,8 @@ export type UpdateState =
| { status: "unavailable" }
| { status: "current" }
| { status: "pending" }
- // The developer pressed the button; the server is going down and coming
- // back, and the page reloads when it has.
+ // The developer pressed the button; the page reloads as soon as the
+ // server has gone down, onto the gate's starting page.
| { status: "restarting" }
| { status: "error"; message: string };
@@ -48,7 +48,7 @@ export interface UpdateStore {
subscribe(listener: () => void): () => void;
/** Ask the router now, outside the poll. */
refresh(): Promise;
- /** POST the update and follow the restart until the server is back. */
+ /** POST the update and reload once the server has gone down. */
apply(): Promise;
}
@@ -106,19 +106,24 @@ export function createUpdateStore(deps: UpdateStoreDeps): UpdateStore {
schedule();
};
- // Follow the restart: the Deployment reports not-ready once the old pod
- // is gone, then ready when the new one answers. Reload on ready after
- // not-ready, or when the clock runs out.
+ // Follow the restart only as far as its first step: the Deployment
+ // reports not-ready as soon as the old pod is gone, and from then on the
+ // router answers a page load with its starting page, which reloads itself
+ // until the new pod is up. Handing over to that page right away is the
+ // point: a bb whose server has just left is a dead UI, every request and
+ // socket failing, and there is nothing it could show that is better than
+ // the gate's own page.
+ //
+ // Waiting for not-ready, rather than reloading at once, keeps the reload
+ // from landing on the old pod in its last moments and loading the full
+ // app only to lose it again.
const follow = async () => {
const started = deps.now();
- let wentDown = false;
while (deps.now() - started < RESTART_TIMEOUT_MS) {
await new Promise((resolve) => deps.setTimeout(resolve, RESTART_POLL_MS));
try {
const s = await get();
- if (s === "unavailable") break;
- if (!s.ready) wentDown = true;
- else if (wentDown) break;
+ if (s === "unavailable" || !s.ready) break;
} catch {
// The router itself is briefly away, or the gateway is; keep waiting.
}
@@ -132,6 +137,14 @@ export function createUpdateStore(deps: UpdateStoreDeps): UpdateStore {
try {
const r = await deps.fetch(UPDATE_PATH, { method: "POST", headers: { Accept: "application/json" } });
if (!r.ok) throw new Error(`bb-gate answered ${r.status}`);
+ const { applied } = (await r.json().catch(() => ({}))) as { applied?: unknown };
+ if (applied === false) {
+ // Nothing to apply after all: the server was already current, or
+ // the quiet window got there first. Nothing restarts, so do not
+ // wait for it to.
+ set({ status: "current" });
+ return;
+ }
} catch (e) {
set({ status: "error", message: e instanceof Error ? e.message : String(e) });
return;