Skip to content

A health tick in flight can overwrite StopAll's "stopped" with "running", so ResumeStopped skips the plugin #1091

Closed

Description

@scttfrdmn

Seen: CI on #1089 (a changelog-only PR) failed TestResumeStoppedRestoresStatusAndHealthLoop with resume_test.go:80: alpha after StopAll = "running", want stopped (run 39071923720). The log shows Plugin alpha: stopping (agent shutdown) before the failure, so StopAll saw alpha as running and saved "stopped", and something wrote "running" afterwards. It didn't reproduce locally in 400 runs (100 with -race), so the window is narrow.

Mechanism (pkg/pluginruntime):

  1. A health tick finishes its check and blocks on rt.mu in recordHealthOK, because StopAll -> stopHealthLoop holds the lock while cancelling the loop.
  2. stopHealthLoop releases the lock. The tick acquires it and Loads the state, still "running": StopAll saves "stopped" outside rt.mu and hasn't done so yet.
  3. StopAll saves "stopped". The tick then saves its copy, "running" with a fresh last_health, over it.

setPluginStatus (degraded after 3 failures) has the same shape.

Effect on a real spore: the plugin reads as running after the agent shutdown. If that stop or hibernate then fails, ResumeStopped (#979) only resumes plugins recorded as stopped, so it skips this one and its health loop is never restored. A plugin that later fails goes unnoticed, which is the #979 bug again, but only in this narrow window.

Fix: both writers take the loop's ctx and return without writing if it is cancelled, checked under rt.mu. stopHealthLoop cancels under that same lock, so a tick that acquires it afterwards always sees the cancel.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions