fix(GRO-2652): reset authInitPromise on failure so retry loop actually retries #225
Reference in New Issue
Block a user
Delete Branch "fix/GRO-2652-auth-promise-reset"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
QA identified a memoization bug in
src/lib/auth.tsduring review of PR #223 (dev→uat):The bug:
initAuth()stores the async IIFE inauthInitPromisebut never clears it on rejection. Theindex.tsstartup retry loop callsinitAuth()up to 10 times, but on attempt 2+:This means the 10-attempt retry loop in
index.tsspins instantly, re-throwing the same rejected promise each time without ever hitting the DB again.Fix
Wrap the final
await authInitPromisein try/catch and resetauthInitPromise = nullon error:Now each time
initAuth()is called after a failure, theif (authInitPromise)guard is falsy and the function creates a fresh attempt (including a fresh DB query retry loop).Acceptance Criteria Traceability
Related
Closes #GRO-2652 (partial — resolves retry memoization bug)
cc @cpfarhood
Previously the initAuth() function set authInitPromise to the async IIFE's Promise but never cleared it on rejection. The index.ts retry loop called initAuth() up to 10 times, but on attempt 2+ the check `if (authInitPromise) { await authInitPromise; return; }` would immediately re-throw the original rejection without performing a real retry. Fix: wrap the final `await authInitPromise` in try/catch and reset authInitPromise = null on error. This allows the index.ts retry loop to create a fresh attempt on each call after a failure. Co-Authored-By: Paperclip <noreply@paperclip.ing>Previously the initAuth() function set authInitPromise to the async IIFE's Promise but never cleared it on rejection. The index.ts retry loop called initAuth() up to 10 times, but on attempt 2+ the check `if (authInitPromise) { await authInitPromise; return; }` would immediately re-throw the original rejection without performing a real retry. Fix: wrap the final `await authInitPromise` in try/catch and reset authInitPromise = null on error. This allows the index.ts retry loop to create a fresh attempt on each call after a failure. Co-Authored-By: Paperclip <noreply@paperclip.ing>