Skip to content

fix: use atomic writes for FileCache to prevent race conditions - #178

Closed
Gosorasora wants to merge 1 commit into
bytecodealliance:mainfrom
Gosorasora:fix/atomic-cache-write
Closed

Gosorasora wants to merge 1 commit into
bytecodealliance:mainfrom
Gosorasora:fix/atomic-cache-write

Conversation

@Gosorasora

Copy link
Copy Markdown

Summary
Fixes race condition when multiple processes access the same cache file concurrently.

Related issue: wasmCloud/wasmCloud#4842

Problem
When two processes write to the same cache file simultaneously, one may read
an incomplete file, causing "unexpected end-of-file" errors.

Solution
Use atomic writes by writing to a temporary file first, then renaming it to
the final path. The rename operation is atomic on most filesystems.

Changes

  • Modified put_data in FileCache to write to temp file first
  • Added atomic rename after write completes

Signed-off-by: Donghyeon Ko <kodh0204@gmail.com>
@Gosorasora Gosorasora closed this by deleting the head repository Dec 16, 2025
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