Repository navigation
fix: handle audit polling timeout state - #632
Conversation
Signed-off-by: Bharadwaj <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
The timeout handling itself is right — the dedicated state, Check again with a fresh deadline, and unhiding the header actions all match #612. One correctness issue in the refactor before merge:
The original effect used a per-invocation let cancelled; this PR switches to a shared cancelledRef that loadAndPoll resets to false on every call. That opens a race when id changes without an unmount (navigating /audit/A → /audit/B re-renders with new params):
- A's loop is asleep in its 3s timeout; cleanup sets
cancelledRef = true. - The new effect immediately calls
loadAndPoll, which resetscancelledRef = false. - A's loop wakes, sees
false, and keeps polling the old id —setAuditthen writes A's results onto B's page.
Suggested fix — a generation counter instead of a shared boolean:
const genRef = useRef(0);
const loadAndPoll = useCallback(async () => {
const gen = ++genRef.current; // this call's token
const cancelled = () => genRef.current !== gen;
// ... use cancelled() everywhere cancelledRef.current is checked
}, [id, tFailed]);
// cleanup: genRef.current++; clearTimeout(...)Each call owns its token, so starting a new poll (Check again or an id change) automatically invalidates every older loop with no shared flag to reset. Happy to re-review once that's in.
Signed-off-by: Bharadwaj <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
The generation-counter fix is exactly right — cleanup only ever advances the counter, so stale loops can never resurrect. Thanks for the quick turnaround!
Summary
Fix audit detail page polling timeout handling. Previously, when an audit remained in
runningstate after the 120-second polling deadline, the page would silently stop polling and keep showing an infinite spinner with no available actions.This change:
timedOutstate when polling reaches the deadline while the audit is still running.Related issue
Closes #612
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)