Skip to content

fix(awsconfig): add file locking to prevent duplicate credential sections#1518

Open
jayjanssen wants to merge 1 commit intoVersent:masterfrom
jayjanssen:jayj/fix-ini-dup-sections
Open

fix(awsconfig): add file locking to prevent duplicate credential sections#1518
jayjanssen wants to merge 1 commit intoVersent:masterfrom
jayjanssen:jayj/fix-ini-dup-sections

Conversation

@jayjanssen
Copy link

@jayjanssen jayjanssen commented Mar 5, 2026

Summary

  • Add exclusive file locking (flock on Unix, LockFileEx on Windows) around the read-modify-write cycle in Save() to prevent concurrent processes from creating duplicate credential sections
  • Use atomic writes (temp file + rename) in saveProfile() to prevent partial writes on crash
  • Add TestConcurrentSave and TestFileLockExclusivity tests with race detector coverage

Test plan

  • go test ./pkg/awsconfig/ -race -count=1 passes
  • GOOS=windows go build ./pkg/awsconfig/ cross-compiles
  • GOOS=linux go build ./pkg/awsconfig/ cross-compiles
  • go build ./... full project compiles
  • Manual: run two concurrent saml2aws login processes, verify no duplicate sections in ~/.aws/credentials

🤖 Generated with Claude Code

…ions

Implement exclusive file locking and atomic writes for the AWS credentials file
to prevent duplicate section headers when multiple saml2aws processes run
concurrently. Use flock on Unix/Linux/macOS and LockFileEx on Windows via
golang.org/x/sys. Add TestConcurrentSave to verify no duplicates under load.

Fixes concurrent race condition in Save() and saveProfile().
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Co-authored-by: Claude Code <noreply@anthropic.com>
Ai-assisted: true
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.

1 participant