Skip to content

fix(api): make HTTP response cache writes atomic#263

Open
baiyuxi930826 wants to merge 1 commit into
cli:trunkfrom
baiyuxi930826:fix/atomic-api-cache-store
Open

fix(api): make HTTP response cache writes atomic#263
baiyuxi930826 wants to merge 1 commit into
cli:trunkfrom
baiyuxi930826:fix/atomic-api-cache-store

Conversation

@baiyuxi930826

Copy link
Copy Markdown

Summary

Fixes #252.

fileStorage.store opened the final cache path with O_TRUNC and wrote the response in place. Concurrent gh processes (mutex is in-process only) or a crash mid-write could leave a partial/corrupt cache entry.

Change

Write to a same-directory temp file (os.CreateTemp), then os.Rename into the final path. On Windows and Unix this is atomic within the same filesystem. Mode remains 0600.

Test plan

  • go test ./pkg/api/ -count=1

Write cache entries to a temp file in the same directory and rename into
place so concurrent gh processes and mid-write crashes cannot leave a
partial or interleaved cache file.

Fixes cli#252
@baiyuxi930826
baiyuxi930826 requested a review from a team as a code owner July 19, 2026 04:30
@baiyuxi930826
baiyuxi930826 requested review from BagToad and removed request for a team July 19, 2026 04:30
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.

API cache is not write-atomic.

2 participants