You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
contract build can expose an empty wasm to concurrent builds #2804
Ran two stellar contract build (or contract deploy/upload auto-build) processes at the same time on the same cargo workspace.
Note that this also happens in the auto_build integration tests and causes builds to fail sometimes. e.g. deploy_workspace_with_package_auto_builds in this run.
What did you expect to see?
Both builds succeed, with each reader seeing either the previous complete wasm or the new complete wasm.
What did you see instead?
The second build fails with ❌ error: unexpected end-of-file (at offset 0x0) after cargo reports Finished. Perhaps writing each rewrite to a temp file in the same directory and renaming it over the target could avoid the empty window while still breaking the deps/ hard link, though there may be other options worth weighing.
Thoughts
After cargo releases its build lock, inject_meta and filter_spec in cmd/soroban-cli/src/commands/contract/build.rs each rewrite the output wasm in place with fs::remove_file followed by fs::write, and fs::write creates an empty file before writing the bytes, so another process reading the same path in that window sees zero bytes. The remove-then-write pattern came from #1896 to break the hard link cargo keeps to deps/ (#1694), and the only step that writes to a temp file and renames into place today is --optimize, while the --out-dir copy uses fs::copy, which is also not atomic.
The file would not exist as a zero length file for a brief period if it was written to a temp directory, or with a random filename in the current directory, then renamed into place after the write is complete. So this is probably the ideal fix.
I don't want to fix it before that PR merges, because that PR adds more cases where a file is rewritten, so I'd like to fix it holistically for all after.
Activity
leighmcculloch commentedon Oct 15, 2026
@fnando I'd like to take fixing this after the following PR merges:
I don't want to fix it before that PR merges, because that PR adds more cases where a file is rewritten, so I'd like to fix it holistically for all after.