fix(#1138): fix SSE EventSource leak and polling race condition (duplicate, conflicts resolved)#1234
Open
ionfwsrijan wants to merge 2 commits into
Open
Conversation
- Add version/generation counter in useTaskSubscription to prevent stale EventSource callbacks from triggering after reconnection - Check versionRef.current against expected version in all SSE event handlers, onerror, and onopen to ignore callbacks from previous connections - Replace setInterval in Scans.tsx with chained setTimeout that awaits loadTasks() before scheduling the next poll - Use AbortController signal to gate polling continuation - Rename intervalRef to pollingTimerRef for clarity
…eout The chained setTimeout pattern calls poll() once immediately on start, unlike setInterval which waits for the first interval. Update the test assertions to reflect the correct call counts.
Contributor
Author
|
@utksh1 Please review this now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Duplicate of #1174 with merge conflicts resolved and rebased onto latest main.
Problem
es.onerrorhandler could firefor the old EventSource after a new connection was established, triggering
spurious reconnection loops and duplicate EventSources.
setInterval(loadTasks, 5000)in Scans.tsx doesn't awaitthe async
loadTasks(). If a request takes longer than 5s, overlappingrequests pile up, potentially corrupting state.
Solution
versionRef(generation counter) touseTaskSubscription.tsthatincrements on every
connectSSE()call and everycleanupAll()status,phase,output,onerror,onopen) now checkversionRef.current === expectedVersionbefore acting — stale callbacks fromprevious connections are silently ignored
Scans.tsx, replacedsetIntervalwith chainedsetTimeout:scheduleNextPoll()awaitsloadTasks()before scheduling the next tickintervalRef→pollingTimerReffor clarityFiles changed
frontend/src/hooks/useTaskSubscription.ts,frontend/src/pages/Scans.tsxCloses #1138