Skip to content

Commit 976130b

Browse files
committed
fix: increase auth retry to 6 with random jitter to handle HF dead replica routing
1 parent 1a84a53 commit 976130b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

frontend/src/pages/LandingPage.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,18 @@ export default function LandingPage({ onGoogleLogin, googleClientId, onAuthSucce
308308
}
309309
};
310310

311-
// Fetch with automatic retry on 503/5xx (HF Space cold-start / rate-limit)
312-
const fetchWithRetry = async (url: string, options: RequestInit, retries = 3): Promise<Response> => {
311+
// Fetch with automatic retry on 503/5xx (HF Space load-balancer multi-replica issue)
312+
// HF free tier has 2 replicas — one may be dead. We retry up to 6 times with random
313+
// jitter so each attempt independently re-rolls the load balancer lottery.
314+
const fetchWithRetry = async (url: string, options: RequestInit, retries = 6): Promise<Response> => {
313315
for (let attempt = 1; attempt <= retries; attempt++) {
314316
const response = await fetch(url, options);
315317
// If 5xx and not last attempt, wait and retry
316318
if (response.status >= 500 && attempt < retries) {
317-
const delay = attempt * 1200; // 1.2s, 2.4s
318-
setErrorMsg(`Server is warming up… retrying (${attempt}/${retries - 1})`);
319-
await new Promise(res => setTimeout(res, delay));
319+
// Random jitter 800ms–1600ms so each retry independently hits the LB
320+
const jitter = 800 + Math.random() * 800;
321+
setErrorMsg(`Connecting to server… retrying (${attempt}/${retries})`);
322+
await new Promise(res => setTimeout(res, jitter));
320323
continue;
321324
}
322325
return response;

0 commit comments

Comments
 (0)