Repository navigation
Conversation
Both production query clients use React Query's defaults, so a looking-glass query whose request timed out, failed on the network or returned a body that isn't JSON was retried three more times with backoff. Each attempt is a new request to the backend and a new session on the device, so one failed submission could reach the device four times, most often when it was already slow or unreachable. Set `retry: false` on the query and remove `retry` from the options a caller can pass, like the other refetch settings. Requerying stays a user action. The new tests use a client with the production defaults rather than the test helper's, which turns retries off for every query.
React Query's `refetchOnReconnect` defaults to true: when the browser fires `online` after a network drop, every mounted result panel sent its query to the backend again, after a success as well as after an error, with no user action. `retryOnMount` also defaults to true, so a failed query is fetched again when a component using it mounts again, even with `refetchOnMount: false`. Nothing remounts a failed result panel today, so this one is defensive. Turn both off and keep callers from overriding them, like `retry`.
WilhelmZA
approved these changes
Nov 21, 2026
WilhelmZA
left a comment
Collaborator
There was a problem hiding this comment.
Approving at c641ec32.
I read the diff against fix/511-abort-controller. useLGQuery now sets retry, refetchOnReconnect and retryOnMount to false and callers can no longer override them. The only caller passes onSuccess and onError, and the requery button still works through refetch(). The new tests use a QueryClient with the production defaults. CI gate passes and both commits are verified.
The base is not main, so Closes #546 does not take effect on this merge. Please retarget this PR to main after #536 merges, or close #546 by hand once the fix is on main. #536 on its own makes a timed-out query retry three times, so the two should reach main together.
Nits:
hyperglass/ui/hooks/use-lg-query.ts:89: the one-line// Don't retry a failed query.follows the three-line comment directly, so it is not clear that the longer comment covers all three settings. A blank line, or dropping the one-liner, would fix that.- The body has a Changelog entry but
CHANGELOG.mdis not edited. Please add it under[Unreleased], here or in the release PR.
This was referenced Nov 21, 2026
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.
Stacked on #536 (#511); review that first. This PR is the commits after it.
Problem
Both production query clients are created with React Query's defaults (
pages/_app.tsx,context/hyperglass-provider.tsx:new QueryClient()), anduseLGQuerydid not setretry. The default retries a query whose function throws 3 more times, waiting 1 s, 2 s and 4 s between attempts.useLGQuery's query function throws on a timeout (AbortError), a network error and a response that isn't JSON. Each retry is a newPOST /api/query, and on a cache miss a new SSH or HTTP session to the device, so one failed submission could reach the device four times. A timed-out query also showed its error only after about four timesrequestTimeout.A JSON error body from the backend (its 4xx/5xx answers) was never retried: the query function returns it as data.
Two other defaults also resent the query without a user action:
refetchOnReconnect(defaulttrue): when the browser firesonlineafter a network drop, React Query refetches every mounted query (Query.onOnline()→observer.refetch(); with the defaultstaleTime: 0every query is stale). Every result panel on screen sent its query again, after a success as well as after an error.retryOnMount(defaulttrue):shouldLoadOnMountfetches a query with no data again when a component using it mounts, even withrefetchOnMount: false, unless the query has failed andretryOnMountisfalse. So a failed query would be resent when its panel remounted. No path in the app was found that remounts a failed result panel, so this one is defensive.The existing tests did not show the retries because
__tests__/render.tsx'smakeQueryClient()turns retries off for every query, and no test covered reconnect or remount.Change
hooks/use-lg-query.ts: setsretry: false,refetchOnReconnect: falseandretryOnMount: falseon the looking-glass query, and adds all three to the options a caller can't override, alongsiderefetchOnWindowFocus,refetchIntervalandrefetchOnMount. The only caller (components/results/individual.tsx) passes justonSuccessandonError. After a query has failed or finished, React Query no longer sends it again on its own; that is left to the user (the requery button, or a new submission).hooks/use-lg-query.test.tsx: newuseLGQuery with the default client optionstests that usenew QueryClient(), i.e. the production defaults, not the test helper's client. Each test checks thatfetchis called once:fetchrejects, and one whose response is not JSON, with fake timers run far pastrequestTimeoutand every default retry delay;onlineevent;The retry tests read
isErrorright after rendering, as a component does in render: React Query v4 re-renders only for result properties that have been read.The settings are on the query, not on a client's
defaultOptions, so they hold whichever client the hook runs under and leaves the other queries as they are.The other queries on these clients
useLGQuery(/api/query)retry,refetchOnReconnectandretryOnMountoff (this PR)useLGQuery(/api/query/{id}/enrichment)fetchin a 1 s interval, not a React Query query, so theretrydefault never applied. A failed poll is logged and the next tick polls again until the status is no longerpendingor the panel unmounts.useDNSQuery(configured DNS-over-HTTPS provider)useWtf(myip.wtf, falling back to/api/myip)/api/myipanswers from the request itselfenabled: false, run only when the user clicks; a retry costs at most two small lookups.useASNDetailenabled: false, and nothing calls ituseHyperglassConfigcomponents/debugger.tsx).There are no
useMutationcalls.Tests
With #536's
use-lg-query.tsand the new tests, all 6 new tests fail:(
expected false to be true: with retries on, the query does not reach the error state while the test waits.)Removing one option at a time, with the full new test set:
Only
retry: falseremoved: 5 fail.Only
refetchOnReconnect: falseremoved: 2 fail.Only
retryOnMount: falseremoved: 1 fails.With the fix:
biome format,biome lint,tsc --noEmitandtestpass;Tests 220 passed (220).Changelog
requestTimeout. Result panels no longer send their query again when the browser comes back online after a network drop, or when a failed result mounts again. Once a query has failed or finished, it is sent again only when the user requeries or submits again (Failed looking-glass queries are retried three times, reaching the device four times #546).Notes
_app.tsxwraps the app in aQueryClientProviderwith its ownnew QueryClient(), andHyperglassProvider, inside it, wraps its children in a secondQueryClientProviderwith the exportedqueryClient. React context resolves to the nearest provider, and every query hook runs belowHyperglassProvider(Meta,Layoutand the pages are its children;HyperglassProvideritself calls no query hook), so the app uses onlyhyperglass-provider.tsx's client.use-form-state.tsimports that same client to remove cached queries. The client in_app.tsxis never used. Not changed here, since the fix doesn't depend on which client runs the query; removing the unused one would be a separate cleanup.AbortError, so the results view does not showmessages.requestTimeout(noted in fix(ui): give each query request its own abort controller and timeout #536).Closes #546