Skip to content

fix(plugins): don't re-read sysinfo in only_os checks - #361

Merged
mudler merged 1 commit into
mudler:masterfrom
jzck:fix/only-os-sysinfo-race
Nov 19, 2026
Merged

mudler merged 1 commit into
mudler:masterfrom
jzck:fix/only-os-sysinfo-race

Conversation

@jzck

@jzck jzck commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #344.

Cause. pkg/plugins keeps the machine's facts in the package-level system, filled once by init(). OnlyIfOS and OnlyIfOSVersion (if_os.go) called system.GetSysInfo() again. In zcalusic/sysinfo v1.1.3 that resets Storage and Network to empty slices and appends to them again (storage.go:67,102, network.go:119,144). Steps of one stage run concurrently (herd DAG), and templateSysData runs json.Marshal(system) for each step it templates. A step with only_os running next to a templated step makes the marshal read a slice whose length is changing:

panic: reflect: slice index out of range
reflect.Value.Index
encoding/json/v2.makeSliceArshaler ...
encoding/json.Marshal
github.com/mudler/yip/pkg/plugins.templateSysData   common.go:36
github.com/mudler/yip/pkg/plugins.Environment       environment.go:59
github.com/mudler/yip/pkg/executor.(*DefaultExecutor).applyStage

It is intermittent and needs an only_os / only_os_version step in the same stage. Kairos's 00_rootfs.yaml has two in rootfs (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 source init() 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_os step under go test -race should show the race before this change.

🤖 Generated with Claude Code

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 mauro-agent left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The description says sysinfo v1.1.3, but master has v1.2.3. The race is the same in both.
  2. Add the race test the description mentions: a templated step beside an only_os step, run with go test -race.
  3. 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.

@Itxaka Itxaka closed this Nov 18, 2026
@Itxaka Itxaka reopened this Nov 18, 2026
@github-project-automation github-project-automation Bot moved this from Under review 🔍 to Done ✅ in 🧙Issue tracking board Nov 18, 2026
@github-project-automation github-project-automation Bot moved this from Done ✅ to Under review 🔍 in 🧙Issue tracking board Nov 18, 2026
@mudler
mudler merged commit e8a2711 into mudler:master Nov 19, 2026
4 of 8 checks passed
@github-project-automation github-project-automation Bot moved this from Under review 🔍 to Done ✅ in 🧙Issue tracking board Nov 19, 2026
@mauromorales

Copy link
Copy Markdown
Collaborator

@jzck thanks for the contribution!

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.

panic: reflect: slice index out of range in plugins.templateSysData

5 participants