fix: detect orphaned builds in WebSocket handler
When build worker returns 404 for >30s or >10 polls, send failed status to client instead of polling forever. Also handled in status API.
This commit is contained in:
1 parent
d3dd51675a
commit
eb403856aa
1 file changed
+11
@@ -43,15 +43,26 @@ function handleBuildWs(ws, buildId) {
|
||||
ws.on("error", () => { closed = true; });
|
||||
|
||||
let lastJson = "";
|
||||
let notFoundCount = 0;
|
||||
const startTime = Date.now();
|
||||
|
||||
const poll = async () => {
|
||||
if (closed) return;
|
||||
try {
|
||||
const res = await fetch(`${BUILD_WORKER_URL}/build/${buildId}/status`);
|
||||
if (!res.ok) {
|
||||
notFoundCount++;
|
||||
// If worker doesn't know this build after 30s, it's orphaned
|
||||
if (res.status === 404 && (notFoundCount > 10 || Date.now() - startTime > 30000)) {
|
||||
const failMsg = JSON.stringify({ status: "failed", message: "Build was lost during a server restart. Please try again.", progress: 0 });
|
||||
try { ws.send(failMsg); } catch {}
|
||||
try { ws.close(1000, "failed"); } catch {}
|
||||
return;
|
||||
}
|
||||
if (!closed) setTimeout(poll, 2000);
|
||||
return;
|
||||
}
|
||||
notFoundCount = 0;
|
||||
const data = await res.json();
|
||||
const json = JSON.stringify(data);
|
||||
|
||||
|
||||
Reference in new issue
Block a user