Skip to content

Conversation

@kichristensen
Copy link
Contributor

What does this change

This fixes an intermittent race condition that causes GitHub Actions builds to fail with the error:

error unmarshalling from mixins package cache.json: invalid character ']' after top-level value
Error: running "bin/porter mixin install docker-compose --version canary --url=" failed with exit code 1

The GetMixins() mage target previously installed mixins in parallel using errgroup.Group. This caused multiple porter mixin install commands to run concurrently, all attempting to read and write the same cache.json file without synchronization.

The savePackageInfo() function performs read-modify-write operations on cache.json without file locking. When multiple processes write simultaneously, the file becomes corrupted with invalid JSON.

Solution: Changed GetMixins() to install mixins sequentially instead of in parallel, ensuring only one process accesses cache.json at a time.

What issue does it fix

This addresses an intermittent CI/CD failure that occurs during the "Configure Agent" step in GitHub Actions workflows when running mage build.

Notes for the reviewer

  • The trade-off is slightly longer build times during mixin installation (sequential vs parallel), but this only affects the initial build when mixins aren't cached
  • The fix eliminates the race condition without requiring more complex file locking mechanisms
  • Existing mixin installation logic remains unchanged - only the parallel execution was removed

Checklist

  • Did you write tests?
    • No tests added. The race condition is intermittent and difficult to reproduce reliably in tests. The fix is straightforward (removing parallel execution).
  • Did you write documentation?
    • No documentation changes needed. This is an internal build process fix with no user-facing changes.
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
    • N/A
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️
    • N/A

Change GetMixins() to install mixins sequentially instead of
in parallel to prevent concurrent writes to cache.json that
were causing intermittent build failures with "invalid
character ']' after top-level value" errors.

The savePackageInfo function performs read-modify-write
operations on cache.json without locking. When multiple
mixin installations ran concurrently via errgroup.Group,
they could corrupt the file during simultaneous writes.

Installing mixins sequentially ensures only one process
accesses cache.json at a time, eliminating the race
condition.

Signed-off-by: Kim Christensen <[email protected]>
@kichristensen kichristensen changed the title fix: prevent race condition in mixin installation Prevent race condition in mixin installation Nov 26, 2025
@kichristensen kichristensen marked this pull request as ready for review November 26, 2025 11:37
@kichristensen kichristensen requested a review from a team as a code owner November 26, 2025 11:37
@kichristensen kichristensen merged commit 8e39750 into getporter:main Nov 26, 2025
45 checks passed
@kichristensen kichristensen deleted the mixinInstallIssue branch November 26, 2025 23:08
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.

2 participants