Skip to content

fix(spored): reload reaches the running daemon (#1278) - #1289

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1278-reload-reaches-daemon
Oct 24, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1278-reload-reaches-daemon

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1278

spored reload used to reload a throwaway agent (NewAgentForQuery) in its own process and print that agent's config. The daemon kept its old config until its periodic refresh. Now:

  • Daemon: runDaemon subscribes to SIGHUP first thing, so a request during startup is queued and does not stop the process. Requests go through Agent.RequestReload, a non-blocking, coalescing channel, into the Monitor select loop. The loop runs Reload on its own goroutine and publishes agent.ReloadMarker (pid, seq, error, config summary incl. TTL deadline and cost limit) to /run/spored/reloaded.json, next to the existing /run/spored/* files. Monitor publishes a seq-0 marker at start.
  • Windows: the service accepts svc.AcceptParamChange, and serviceControlAction maps ParamChange to the same request. spored reload sends ParamChange through the SCM. The marker goes to %PROGRAMDATA%\spored\reloaded.json.
  • spored reload:
    1. Finds the daemon's pid (systemctl show --property=MainPID spored, or the SCM's ProcessId).
    2. Refuses to signal if the marker's pid isn't that daemon. That catches an older spored, which has no SIGHUP handler and would be killed.
    3. Signals, then polls up to about 15 s for a newer seq from that pid, and prints the daemon's config.
    4. Exits non-zero if spored isn't running, doesn't acknowledge, or reported a refresh error.
  • spored config set: notifies the daemon the same way and no longer runs a throwaway reload. The ttl read-back now comes from the daemon's marker.
  • Agent.Reload: reads and swaps the config through cfg()/setConfig.
  • spawn extend: the command string is unchanged. Its success line now says the daemon reloaded.

Deviation from the plan: the plan said systemctl kill -s HUP spored. This signals the unit's main pid instead. By default systemctl kill signals every process in the cgroup, which includes plugin steps spored runs (pkg/pluginruntime), and SIGHUP would kill them. The pid is also needed for the marker check. The unit file is not touched.

Gates (each watched failing against a revert that compiles):

  • TestMonitor_ReloadRequestRefreshesRunningAgent: a running Monitor with a 1h ticker. The test changes the stub's config, requests a reload, then asserts the running agent adopted it, exactly 1 RefreshConfig, configRefreshTick == 0, and a marker with seq 1. Revert (drop the select case): the test fails waiting for the request.
  • TestReload_SwapsUnderConfigMu: concurrent GetConfig under -race, plus Reload blocking while configMu is held. Revert to a.config = newConfig (write only, or read+write): DATA RACE / "completed while configMu was held".
  • TestReload_NoDaemonFails, TestReload_NoAcknowledgementFails (bound counted in polls), TestReload_IgnoresMarkersThatAreNotTheAcknowledgement, TestReload_DoesNotSignalADaemonWithoutAMarker: reverting the pid==0 check, or returning success on no ack, fails them.
  • TestNotifyReload_SIGHUP: subscribing a different signal kills the test binary with SIGHUP.
  • Windows-only TestServiceControl_ParamChangeReloads / TestRequestReload_ReachesNotifyReload: compiled locally with GOOS=windows only; they run on the Windows CI job.

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.98343% with 67 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/spored/reload_other.go 51.51% 16 Missing ⚠️
cmd/spored/main.go 31.81% 14 Missing and 1 partial ⚠️
cmd/spored/reload.go 74.07% 10 Missing and 4 partials ⚠️
pkg/agent/reload.go 72.54% 7 Missing and 7 partials ⚠️
pkg/agent/agent.go 57.89% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

spored reload used to reload a throwaway agent in its own process. It now
signals the daemon (SIGHUP to the unit's main pid; SCM ParamChange on
Windows); the monitor loop refreshes and publishes /run/spored/reloaded.json,
which reload waits for and prints. Non-zero when the daemon is not running,
does not acknowledge, or failed to refresh. config set notifies the same way.
Agent.Reload now reads and swaps config under configMu.

Fixes #1278
@scttfrdmn
scttfrdmn force-pushed the fix/1278-reload-reaches-daemon branch from 1bd8ed7 to 3d98b20 Compare October 24, 2026 04:44
@scttfrdmn
scttfrdmn merged commit b1d35d1 into main Oct 24, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1278-reload-reaches-daemon branch October 24, 2026 04:58
@scttfrdmn scttfrdmn mentioned this pull request Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spored reload never reaches the running daemon: it reloads a throwaway agent in its own process

1 participant