Skip to content

fix(auth): retry reading a session file while it is replaced on Windows - #275

Merged
pjcdawkins merged 3 commits into
mainfrom
fix-auth-store-windows-read
Oct 26, 2026
Merged

pjcdawkins merged 3 commits into
mainfrom
fix-auth-store-windows-read

Conversation

@pjcdawkins

@pjcdawkins pjcdawkins commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

TestAuthRefresh_ManyExpiries failed on Windows in a CI run of #272 (it passed on a re-run):

open …\.platform-test-cli\auth\default.json: The process cannot access the file because it is being used by another process.

With Go auth, the file store replaces a session file with a rename, which WriteFileAtomic retries on Windows while another process has the file open. Reads of the file, outside the lock, had no retry, so a command that read it during a rename failed with a sharing violation. Reads now retry on a sharing violation, as the rename does (store.ReadFile). The migration marker, the other file that WriteFileAtomic writes, is read the same way.

TestReadFileWhileReplaced (Windows only) reads a file while it is replaced 500 times. Run in a Windows 11 VM, 10–19 plain reads failed in each run, and none with the retry. CI runs Go unit tests on Linux only, so it doesn't run there.

🤖 Generated with Claude Code

The file store replaces a session file with a rename, which retries on
Windows while another process has the file open. Reading it had no retry, so
a command reading the file during the rename failed with a sharing
violation, as in TestAuthRefresh_ManyExpiries. Reads now retry on a sharing
violation in the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Changes suggested — 🟡 1 warning

🔍 Full review · 4 files reviewed

Verification
  • readFile returns the error unchanged once the error is not a sharing violation, so readSessionFile still maps fs.ErrNotExist to (nil, nil).
  • The read retry has the same bounds as the rename retry in WriteFileAtomic: 41 attempts with 25ms sleeps.
  • sharing_windows.go and sharing_windows_test.go are limited to Windows by their _windows file-name suffix, and sharing_other.go has the matching !windows tag. golang.org/x/sys is already a direct requirement in go.mod.
  • The test uses sync.WaitGroup.Go, which is supported by the module's go 1.27.1 directive.

The only coverage is the new TestReadFileWhileReplaced, which is Windows-only. Per the PR description, CI runs the Go unit tests on Linux only, so no automated check runs this test or reaches the retry branch.

Review details
  • Commit: 653915a
  • Model: claude-opus-5-5

Review 1 of 10 for this pull request · View the full run

Comment thread internal/auth/store/store.go Outdated
The migration marker is also written by WriteFileAtomic, and read outside
the migration lock. Export the retrying read as store.ReadFile and use it
there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pjcdawkins
pjcdawkins enabled auto-merge (squash) October 26, 2026 20:24
@pjcdawkins
pjcdawkins merged commit 1acf680 into main Oct 26, 2026
11 checks passed
@pjcdawkins
pjcdawkins deleted the fix-auth-store-windows-read branch October 26, 2026 20:28
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