fleet icon indicating copy to clipboard operation
fleet copied to clipboard

Dashboard's WelcomeHost card repeats 'vitals taking longer than expected' toast indefinitely

Open Leanngove opened this issue 4 months ago • 3 comments

Fleet versions

  • Discovered: main (current dev branch, 4.90.0-ish)
  • Reproduced: main

Web browser and operating system: Chrome, macOS


💥 Actual behavior

In frontend/pages/DashboardPage/cards/WelcomeHost/WelcomeHost.tsx, once a host's refetch_requested flag stays true for an extended period (e.g., the host stops checking in after a refetch is requested), the "Vitals are taking longer than expected to load." toast — and the disabled/spinner state on the Refetch button — can repeat indefinitely instead of settling into a single terminal state.

Root cause: the useQuery onSuccess handler's give-up branch (elapsed time >= 60000ms) only calls setShowRefetchLoadingSpinner(false). It never resets refetchStartTime back to null. Compare this to the equivalent give-up branches in frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx and frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx, which both call a resetHostRefetchStates() helper that resets both the spinner and refetchStartTime.

Because refetchStartTime is left pinned to the original stale timestamp, any later refetch of the ["host"] query (e.g., React Query's default refetchOnWindowFocus, a tab switch, or any other trigger that re-runs the query while refetch_requested is still true server-side) immediately recomputes totalElapsedTime as far past the 60s threshold and fires the toast again — repeatedly, without the user doing anything.

Separately, the very first line of that onSuccess handler unconditionally does setShowRefetchLoadingSpinner(returnedHost.refetch_requested), so the Refetch button can appear disabled/"actively refetching" on every render as long as the flag stays true, even outside an active polling window.

🛠️ Expected behavior

The toast should fire once per stalled refetch attempt, not repeatedly on every incidental re-fetch of host data. After giving up, the component's refetch-timer state should fully reset (mirroring resetHostRefetchStates() in HostDetailsPage.tsx/DeviceUserPage.tsx) so a later, unrelated re-fetch of the host doesn't immediately re-trigger the give-up path.

🧑‍💻 Steps to reproduce

These steps:

  • [ ] Have been confirmed to consistently lead to reproduction in multiple Fleet instances.
  • [x] Describe the workflow that led to the error, but have not yet been reproduced in multiple Fleet instances.
  1. In a local dev instance with exactly one host (id 1) and at least one policy result recorded for it, load the Dashboard so the WelcomeHost "Welcome to Fleet" card renders with the Refetch button.
  2. Click Refetch, then stop the host's agent process (or otherwise ensure it can never submit another distributed write) while keeping the host's seen_time fresh enough that Fleet still reports it as "online" (e.g. via hosts.distributed_interval/hosts.config_tls_refresh in the dev DB).
  3. Wait ~60 seconds — the "Vitals are taking longer than expected to load." toast fires and the Refetch button re-enables, as expected.
  4. Leave refetch_requested stuck true in the DB (agent still stopped) and switch away from/back to the browser tab (or otherwise trigger React Query's refetchOnWindowFocus).
  5. Observe the toast fires again immediately, and this repeats on every subsequent window focus / re-fetch, indefinitely.

🕯️ More info (optional)

Likely fix: add a resetHostRefetchStates()-equivalent call (resetting both showRefetchLoadingSpinner and refetchStartTime) to WelcomeHost.tsx's give-up branch, matching the pattern already used in HostDetailsPage.tsx and DeviceUserPage.tsx. Worth considering whether WelcomeHost.tsx should get its own small resetHostRefetchStates helper for consistency, since it currently resets spinner/timer state inline in several places.

Leanngove avatar Jul 15 '26 23:07 Leanngove

I'd like to take a shot at this; opened a fix here: #53824. Added resetHostRefetchStates() matching the pattern already in HostDetailsPage.tsx/DeviceUserPage.tsx, plus a regression test that simulates the window-focus re-fetch from the repro steps and fails without the fix (toast fires twice) / passes with it.

jdscreations avatar Sep 23 '26 13:09 jdscreations

Welcome card refetch toast loop (#49381) — fixed on main ✅

Environment: main @ 04a85078f0 (includes #53824) vs 3514dd5f6a (before #53824), Premium, two fresh single-host instances. Host 1 is an osquery-perf Mac that stays online but doesn't answer the refetch. Driven in the dashboard UI, with toasts and host re-fetches counted. #53824 is on main only, so this lands in 4.94.0.

1. Window focus after the give-up toast — ✅ no new toast. Before: every focus fired "Refetch sent but vitals are taking longer than expected to load" again right away (3 focuses = 3 more toasts).

2. Give-up — ✅ unchanged: one toast about 60s after clicking Refetch, then the button re-enables and polling stops.

3. Focus while the host is still stuck — ✅ the card now behaves like Host details: the focus starts a new 60s refetch window and shows one toast when that window ends, then goes quiet. Over 3 focuses plus 5 minutes idle: 2 toasts on the fix vs 4 before.

4. Responsive host — ✅ unchanged: Refetch clears in about 4s with no toast, and a later focus does nothing.

5. Dashboard opened while the refetch is already stuck — ✅ unchanged: the button stays disabled for 60s, one toast, then it re-enables.

Ready to close ✅

Image

Brajim20 avatar Oct 02 '26 17:10 Brajim20

Stale timer haunts each window focus restarts reset clears the fog

fleet-release avatar Oct 29 '26 00:10 fleet-release