Skip to content

pkg/agent: Monitor takes ~14s to return after cancel on the Windows runner, so #1102's 10s wait in TestMonitor_SpotDetectionDoesNotGateTicker fails #1104

Closed

Description

@scttfrdmn

Seen: Test (Windows) on PR #1103, which doesn't touch pkg/agent (run 39083879825, job 117546278626):

--- FAIL: TestMonitor_SpotDetectionDoesNotGateTicker (10.04s)
    agent_test.go:656: Monitor did not return after its context was cancelled

#1102 (merged about an hour earlier) added that 10s wait for Monitor to return in the test's cleanup.

Timeline from the same log (shared log output):

  • ~00:46:57: the test body ends and cleanup calls cancel();
  • 00:47:07: the 10s wait gives up and the test fails;
  • 00:47:07: monitor tick 1, then TTL expired … Terminating instance … Running cleanup tasks … Cleanup complete … Warning sent to users;
  • 00:47:11: Context cancelled, stopping monitor.

So Monitor did return, but about 14s after cancellation. Either a tick already in flight runs work that doesn't watch the context, or the warning/cleanup path is slow on Windows. Both are plausible from the log; I haven't established which.

Why it matters beyond the test: spored's shutdown waits on this loop. If a tick can delay cancellation by 10+ seconds on Windows, that delay also exists on real Windows spores.

Options: make the tick's work honour the context (the real fix, if that's the cause), or give the test a wait that reflects Monitor's worst-case tick on Windows. Rerunning CI to get past it is not a fix.

I'm re-running the job for #1103, since this code isn't touched there.

Activity

  1. scttfrdmn commented on Oct 18, 2026

    @scttfrdmn
    ContributorAuthor

    Recurring: it failed again on #1083, a docs-only PR (job 117557620705), the same way. That's 2 of the last 3 Windows runs I've seen.

    Likely mechanism, from the code (not yet measured):

    • Monitor exits only between ticks: select { case <-ctx.Done(): return; case <-ticker.C: a.checkAndAct(ctx) } (pkg/agent/agent.go:546). So it can't return until a checkAndAct already in flight finishes.
    • On Windows, every metric reader shells out to a fresh powershell -NoProfile process (psOutput, pkg/agent/sys_windows.go:26, using exec.Command, not CommandContext), or to quser / msg. None of them take the context, and a PowerShell cold start on a CI runner is seconds. A tick that runs several readers can plausibly exceed 10s.
    • Suspected trigger: if spored status shows the daemon's idle readings instead of a one-shot sample (#1090) #1095 (spawn status / spored status always show CPU, network and disk I/O as "unknown (single sample)" #1090) made each tick evaluate idleness even with no --idle-timeout (to publish idle-state.json), then every tick now runs those PowerShell readers. Before, a test with an empty config barely shelled out at all. Worth confirming: run checkAndAct once on the Windows runner and time it.

    Effect on a real Windows spore: shutdown, hibernate prep and ResumeStopped wait on the loop, so each can stall by the length of one tick.

    Fix shape: make the Windows readers context-aware (exec.CommandContext with the tick's context). Better still, take every Windows sample from a single PowerShell process per tick rather than one process per reader. Raising the test's wait would hide the cost, not remove it.

  2. added this to the v0.135.2 milestone on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions