fix(preview): add 60-second grace period before marking freshly booted servers as zombies to prevent aggressive 502 teardowns

This commit is contained in:
2026-06-12 16:49:31 -07:00
parent 95253c7707
commit aa780492fd
2 changed files with 17 additions and 1 deletions

View File

@@ -126,6 +126,7 @@ export default function PreviewTab() {
if (primaryRunning || primaryStarting) return; // already up or already starting
ensureCalledRef.current = true;
setEnsureStatus("calling");
fetch(`/api/projects/${projectId}/dev-server/ensure`, {
method: "POST",
@@ -144,7 +145,14 @@ export default function PreviewTab() {
}
})
.catch(() => setEnsureStatus("error"));
}, [loading, anatomy, primaryRunning, primaryStarting, projectId]);
}, [
loading,
anatomy,
primaryRunning,
primaryStarting,
projectId,
refreshKey,
]);
const [iframeSrc, setIframeSrc] = useState<string | null>(null);
const iframeDomRef = useRef<HTMLIFrameElement | null>(null);

View File

@@ -825,6 +825,14 @@ async function loadPreviews(projectId: string): Promise<Preview[]> {
ping.status === 504 ||
ping.status === 404
) {
// Give freshly booted servers a 60-second grace period before murdering them.
// Traefik sometimes returns 502 for a few seconds right after the internal probe succeeds.
const ageMs = Date.now() - new Date(r.started_at).getTime();
if (ageMs < 60000) {
activePreviews.push(r);
return;
}
console.warn(
`[anatomy] Preview zombie detected for ${r.preview_url} (HTTP ${ping.status}). Marking stopped.`,
);