Repository navigation
fix(plugins): don't re-read sysinfo in only_os checks - #361
Conversation
OnlyIfOS and OnlyIfOSVersion called system.GetSysInfo() on the package-level `system`, which init() already fills. GetSysInfo resets Storage and Network to empty slices and appends to them again, while steps of the same stage run concurrently and templateSysData marshals `system`. A step with only_os next to a templated step races on those slices, and the marshal panics with "reflect: slice index out of range". The OS name and version do not change during a run, so the values from init() are enough. Fixes mudler#344 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mauro-agent
left a comment
There was a problem hiding this comment.
Review of the diff only. I did not build or run it.
The fix is correct. system is filled once in init() (pkg/plugins/common.go). OnlyIfOS and OnlyIfOSVersion called system.GetSysInfo() again. That call resets Storage with make(..., 0) and appends to it (storage.go, same in v1.1.3 and v1.2.3). templateSysData runs json.Marshal(&system) while steps run concurrently, so the marshal can read a slice that is changing. That matches the panic in #344. Nothing else in the package writes to system, so dropping the re-read removes the race.
One behaviour change: the OS name and version are now read once at process start, not per step. It differs only if an earlier stage rewrites /etc/os-release and a later step uses only_os. A line in the description would cover it.
Requests:
- The description says sysinfo v1.1.3, but
masterhas v1.2.3. The race is the same in both. - Add the race test the description mentions: a templated step beside an
only_osstep, run withgo test -race. - No CI checks are reported on this head, so I cannot say the existing tests pass.
Recovering from the panic (#348) would hide this race, as the description says, so I would keep that separate.
|
@jzck thanks for the contribution! |
Fixes #344.
Cause.
pkg/pluginskeeps the machine's facts in the package-levelsystem, filled once byinit().OnlyIfOSandOnlyIfOSVersion(if_os.go) calledsystem.GetSysInfo()again. In zcalusic/sysinfo v1.1.3 that resetsStorageandNetworkto empty slices and appends to them again (storage.go:67,102,network.go:119,144). Steps of one stage run concurrently (herd DAG), andtemplateSysDatarunsjson.Marshal(system)for each step it templates. A step withonly_osrunning next to a templated step makes the marshal read a slice whose length is changing:It is intermittent and needs an
only_os/only_os_versionstep in the same stage. Kairos's00_rootfs.yamlhas two inrootfs(only_os: "Alpine.*"). We saw it there on a Kairos Alpine image built with Go 1.27.3: the machine stopped in the initramfs emergency shell, and a reset booted the same image.Fix. Drop the re-read. The OS name and version don't change during a run, so the values
init()read are enough. The existing tests read the host's/etc/os-release, the same sourceinit()uses.About #348. Recovering from the panic hides the race: the template comes back uninterpolated and the step runs with unrendered values.
Not done. I did not add a race test. Running a templated step beside an
only_osstep undergo test -raceshould show the race before this change.🤖 Generated with Claude Code