Fix hiera.yaml write race in the pupmod spec_helper template - #91
Draft
silug wants to merge 1 commit into
Draft
Conversation
The config-level before(:all) hook rewrites spec/fixtures/hieradata/hiera.yaml with a truncating write before every top-level example group. Under `rake parallel_spec`, every worker runs this hook, and a catalogue compile in another worker that reads hiera.yaml inside the truncate-to-write window sees an empty hiera config and silently compiles without any custom hieradata. This is the confirmed root cause of the fleet-wide random hieradata-not-applied spec failures (ref simp#90) — not the set_hieradata global-state design originally suspected. Reproduced deterministically in pupmod-simp-simplib by rewriting hiera.yaml in a tight loop while running dlookup_spec (simp/pupmod-simp-simplib#362, fixed there by simp/pupmod-simp-simplib#363 with this same change). Write the file atomically instead: write to a PID-suffixed temp file in the same directory and rename it into place. Readers then always see a complete hiera.yaml. The temp file must be in the same directory -- rename(2) is only atomic within a filesystem. Ref simp#90 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref #90
Root cause of the fleet-wide random hieradata-not-applied failures
The config-level
before(:all)hook in the pupmodspec_helper.rbtemplate rewritesspec/fixtures/hieradata/hiera.yamlwith a truncatingFile.open(..., 'w')before every top-level example group. Underrake parallel_spec, every worker runs this hook — so a catalogue compile in one worker that readshiera.yamlinside another worker's truncate-to-write window sees an empty hiera config and silently compiles without any custom hieradata (falling back to code defaults). This matches every failure signature collected in #90; theset_hieradataglobal-state design originally suspected there was ruled out — a simplib PR that bypassed it entirely still hit the flake in its own CI run.Confirmed by deterministic reproduction in pupmod-simp-simplib (simp/pupmod-simp-simplib#362): rewriting
hiera.yamlin a tight truncate-then-write loop while runningdlookup_specproduced the exact CI failure on the first run; with atomic rewrites, 8/8 runs passed under the same concurrent load. Fixed there per-module in simp/pupmod-simp-simplib#363 with this same change.Change
Write
hiera.yamlatomically: write to a PID-suffixed temp file in the same directory (rename(2) is only atomic within a filesystem) andFile.renameit into place. Readers then always see a complete file.Status
Draft: held until the in-flight template-refresh work merges, then this should ride the next baseline sync across the fleet. Note that simp/pupmod-simp-simplib#363 patched its module-local copy directly — the synced template must include this fix or the next sync will regress it.
🤖 Generated with Claude Code