Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(gates): a relaunch waits for the GPU process to come back

esenginead5223416dcb
diff --git a/desktop/tests/dead-gpu.test.ts b/desktop/tests/dead-gpu.test.ts
index 1ca2626e1..fea5d975e 100644
--- a/desktop/tests/dead-gpu.test.ts
+++ b/desktop/tests/dead-gpu.test.ts
@@ -25,6 +25,7 @@ function run(outputs: Array<string | null>) {
return { ok: out === null, output: out ?? '' };
},
(died: boolean) => notes.push(died),
+ 0, // no backoff: there is no GPU process to wait for here
);
return { ...result, attempts, notes };
}
@@ -80,7 +81,7 @@ describe('retryOnDeadGpu', () => {
it('gives up at the cap and says the GPU is why', () => {
const r = run([DEAD]);
expect(r.ok).toBe(false);
- expect(r.attempts).toBe(3);
+ expect(r.attempts).toBe(4);
expect(r.gpuDied).toBe(true);
});
});
diff --git a/tools/lib/deadGpu.mjs b/tools/lib/deadGpu.mjs
index 2dfeb2c59..f55f7db84 100644
--- a/tools/lib/deadGpu.mjs
+++ b/tools/lib/deadGpu.mjs
@@ -22,7 +22,18 @@ export function gpuNeverCameUp(output) {
}
/** Attempts one measurement is allowed, counting the first. */
-const MAX_ATTEMPTS = 3;
+const MAX_ATTEMPTS = 4;
+
+/**
+ * Wait before relaunching, growing with each try. The retries were immediate,
+ * which relaunches into a GPU process still on its way down — three attempts
+ * inside a second are one attempt with extra steps. Synchronous because the
+ * launches are; `stepMs` is 0 in tests, which have no process to wait for.
+ */
+function backoff(attempt, stepMs) {
+ if (stepMs <= 0) return;
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, stepMs * (attempt + 1));
+}
/**
* Run `attempt` (→ `{ ok, output }`) until it succeeds or fails with the GPU up.
@@ -32,7 +43,7 @@ const MAX_ATTEMPTS = 3;
* nothing about why. A game that truly draws nothing still fails on the first
* attempt, since no attempt reports a death. `note(died)` announces each retry.
*/
-export function retryOnDeadGpu(attempt, note) {
+export function retryOnDeadGpu(attempt, note, stepMs = 2000) {
let sawDeath = false;
let last;
for (let i = 0; i < MAX_ATTEMPTS; i++) {
@@ -42,7 +53,10 @@ export function retryOnDeadGpu(attempt, note) {
sawDeath = sawDeath || died;
// Nothing in this chain blamed the GPU, so the failure is the game's.
if (!sawDeath) return { ...last, retried: i > 0 };
- if (i < MAX_ATTEMPTS - 1) note(died);
+ if (i < MAX_ATTEMPTS - 1) {
+ note(died);
+ backoff(i, stepMs);
+ }
}
return { ...last, retried: true, gpuDied: true };
}