Skip to content

blockifier_test_utils: fix ETXTBSY race in cairo package download#13850

Merged
dorimedini-starkware merged 1 commit into
mainfrom
avi/cherry-pick-fix-compiler-download-race
Apr 23, 2026
Merged

blockifier_test_utils: fix ETXTBSY race in cairo package download#13850
dorimedini-starkware merged 1 commit into
mainfrom
avi/cherry-pick-fix-compiler-download-race

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

verify_cairo1_package double-checks cairo1_package_exists — once
without the lock (fast path) and once after acquiring it. The predicate
only tested .exists() on the two binaries, so a concurrent process
could observe the package as "ready" while tar was still mid-write:

  1. Process A holds the download lock, tar is extracting the archive.
  2. tar extracts sequentially: first binary is closed, second binary
    is created (so .exists() is true) and being written to.
  3. Process B calls cairo1_package_exists, sees both files, skips the
    lock.
  4. Process B forks + execs the second binary → Linux returns
    ETXTBSY because the file is still open for writing by tar.

Fix with the same commit-marker pattern used in compile_cache.rs:
write .download_complete after tar finishes, and require it in
cairo1_package_exists. Until the marker exists, concurrent callers
fall through to the lock and wait for the writer.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

`verify_cairo1_package` double-checks `cairo1_package_exists` — once
without the lock (fast path) and once after acquiring it. The predicate
only tested `.exists()` on the two binaries, so a concurrent process
could observe the package as "ready" while `tar` was still mid-write:

1. Process A holds the download lock, `tar` is extracting the archive.
2. `tar` extracts sequentially: first binary is closed, second binary
   is created (so `.exists()` is true) and being written to.
3. Process B calls `cairo1_package_exists`, sees both files, skips the
   lock.
4. Process B forks + execs the second binary → Linux returns
   `ETXTBSY` because the file is still open for writing by `tar`.

Fix with the same commit-marker pattern used in `compile_cache.rs`:
write `.download_complete` after `tar` finishes, and require it in
`cairo1_package_exists`. Until the marker exists, concurrent callers
fall through to the lock and wait for the writer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 23, 2026

PR Summary

Low Risk
Low risk: adds a simple completion marker check to avoid concurrent processes executing partially extracted binaries; behavior change is limited to test-utils package download flow.

Overview
Fixes a race in Cairo1 compiler package setup where concurrent callers could treat the package as ready while tar was still writing binaries, leading to ETXTBSY on exec.

The download now writes a .download_complete marker after extraction finishes, and cairo1_package_exists requires this marker in addition to the compiler binaries so the fast-path only returns true for fully extracted packages.

Reviewed by Cursor Bugbot for commit 603c4ae. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

@dorimedini-starkware reviewed 1 file and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on avi-starkware).

Copy link
Copy Markdown
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on avi-starkware).

@dorimedini-starkware dorimedini-starkware added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit 4876f07 Apr 23, 2026
37 of 50 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants