fleet icon indicating copy to clipboard operation
fleet copied to clipboard

fleetctl trigger silently no-ops for WithRunOnce schedules after a restart (found while QA'ing #36365 fix)

Open marcusallen97 opened this issue 3 months ago • 4 comments

Fleet versions

  • Discovered: 4.91.0-rc.2608171507 (branch rc-minor-fleet-v4.91.0)
  • Reproduced: 4.91.0-rc.2608171507 (branch rc-minor-fleet-v4.91.0)

Web browser and operating system: N/A — reproduced via fleetctl trigger, direct MySQL queries, and Go source inspection against a local dev server on macOS; no browser UI involved.


💥 Actual behavior

fleetctl trigger --name software_checksum_migration (the documented remediation for #36365 — "Duplicate CVE entries for giflib 5.2.2" — if duplicate software inventory rows are still present after upgrading) silently does nothing once the migration has completed successfully one time and the server has been restarted since. The command reports success ("Sent request to trigger software_checksum_migration schedule") and returns no error, but no reconciliation actually runs.

Root cause: cronSoftwareChecksumMigration (added in PR #50427, changed to auto-run via PR #50490) is registered with schedule.WithRunOnce(true). Schedule.Start() (server/service/schedule/schedule.go) contains:

} else if s.runOnce && prevScheduledRun.Status == fleet.CronStatsStatusCompleted {
    // If job is set to run once, and it already ran, then nothing to do
    return
}

prevScheduledRun is read from the persisted cron_stats table, not an in-memory flag. So on any server restart after one completed run, every future Start() call for this schedule hits this branch and returns before the goroutine that listens on the schedule's trigger channel is ever created.

However, CronSchedules.StartCronSchedule (server/fleet/cron_schedules.go) still registers the schedule in the running-schedules map unconditionally:

sched.Start()
cs.Schedules[sched.Name()] = sched

So TriggerCronSchedule finds the schedule by name (no "not found" error), calls sched.Trigger(ctx), which attempts a non-blocking send on the trigger channel:

select {
case s.trigger <- 0:
    didTrigger = true
default:
    s.logger.DebugContext(ctx, "trigger channel not available")
}
return nil, didTrigger, nil

Since nothing is listening (the goroutine was never created), this always falls to default:, logs only at DEBUG level, and returns (nil, false, nil) — no error. TriggerCronSchedule's caller sees err == nil and stats == nil and reports success.

This also means the "runs daily thereafter" behavior described in PR #50490's release notes only holds for the lifetime of a single continuously-running process — a restart resets everything, and the same early-return prevents the daily ticker from ever being set up again either.

Not a new pattern: the identical WithRunOnce(true) construction already exists in cronUninstallSoftwareMigration and cronUpgradeCodeSoftwareMigration (cmd/fleet/cron.go), predating this ticket. PR #50490 copied an existing, already-flawed pattern onto a third schedule rather than introducing a new one — meaning uninstall_software_migration and upgrade_code_software_migration most likely have the identical bug today.

Verified live against main/rc-minor-fleet-v4.91.0 (commit 1ba789a263a5):

  1. Confirmed via cron_stats that software_checksum_migration had one completed row from an earlier server startup.
  2. fleetctl trigger --name software_checksum_migration against the then-running server produced no new cron_stats row and no change to a manually-inserted duplicate-checksum pair for giflib 5.2.2/homebrew_packages.
  3. Deleted the stale cron_stats row and restarted the server — Start() then proceeded normally, the migration ran automatically, and a fresh manual trigger did work (and was idempotent on a second call) — all within that same process.
  4. Confirms the break is specifically "next restart after a completed run persists," not "immediately after any single completion."

🛠️ Expected behavior

fleetctl trigger --name software_checksum_migration (and the equivalent for uninstall_software_migration / upgrade_code_software_migration, if they share this bug) should actually re-run the job whenever invoked, regardless of how many times the server has restarted since the job last completed — matching what the PR's own documentation and release notes describe. At minimum, TriggerCronSchedule should surface an error when a schedule is registered but its listener was never started, rather than silently reporting success.

🧑‍💻 Steps to reproduce

  • [x] Have been confirmed to consistently lead to reproduction in multiple Fleet instances.
  1. On a Fleet instance with the fix for #36365 (software_checksum_migration registered with WithRunOnce(true)), let the server start up normally so the migration runs once and cron_stats records a completed row for software_checksum_migration.
  2. Restart the Fleet server (any restart — deploy, pod reschedule, manual restart).
  3. Insert a duplicate-checksum software pair directly (or otherwise reproduce #36365's duplicate-row scenario).
  4. Run fleetctl trigger --name software_checksum_migration.
  5. Observe: command reports success, but no new cron_stats row is created and the duplicate is not merged.
  6. (To confirm the mechanism) Delete the completed cron_stats row for this schedule and restart the server again — the trigger will work correctly within that process, until the next restart.

🕯️ More info (optional)

  • Related: #36365 ("Duplicate CVE entries for giflib 5.2.2"), fixed by fleetdm/fleet#50427 and fleetdm/fleet#50490
  • This is a follow-up finding from QA'ing #36365's fix, not a new independent bug report unrelated to it. The core duplicate-merging logic (ReconcileSoftwareChecksums) is correct and well-tested — verified directly via a live reproduction using the exact real pre/post-v4.76.0 checksum formulas for giflib 5.2.2. This ticket is specifically about the scheduling/trigger wrapper around that logic.
  • Worth checking whether cronUninstallSoftwareMigration and cronUpgradeCodeSoftwareMigration have the same issue, since they use the identical WithRunOnce(true) pattern.
  • Relevant code: server/service/schedule/schedule.go (Start(), Trigger()), server/fleet/cron_schedules.go (StartCronSchedule, TriggerCronSchedule), cmd/fleet/cron.go (cronSoftwareChecksumMigration and the two other WithRunOnce schedules).

marcusallen97 avatar Aug 19 '26 13:08 marcusallen97

This is expected - the server was updated so that the bug is not introduced again. software_checksum_migration is meant to be run once to fix existing data (the reason why it was not added as a migration due to possible performance issues).

If the run was successful, the user shouldn't need to run software_checksum_migration again - and we should probably be good to remove that job altogether in a subsequent release.

juan-fdz-hawa avatar Aug 20 '26 16:08 juan-fdz-hawa

Schedules sleep after restart trigger channel never wakes silent success lies

fleet-release avatar Aug 25 '26 20:08 fleet-release

Closing issue since @juan-fdz-hawa mentioned this was as-designed.

marcusallen97 avatar Aug 25 '26 20:08 marcusallen97

Schedules persist through restarts but listeners fade to silence trigger brings no change

fleet-release avatar Aug 25 '26 20:08 fleet-release