Skip to content

download_file: publish downloads atomically - #1561

Open
martinpitt wants to merge 2 commits into
facebook:mainfrom
martinpitt:download-atomic
Open

martinpitt wants to merge 2 commits into
facebook:mainfrom
martinpitt:download-atomic

Conversation

@martinpitt

Copy link
Copy Markdown
Contributor

A download with a declared checksum and size writes straight to its
content-based path, which has no configuration component. A target
analyzed under several configurations downloads that path once per
configuration, and each download removed what was there and wrote the
file in place. A consumer of the download that finished first could find
the file missing, empty or half written.

Commit 19c7323 fixed this kind of race for write actions. Do the same
for downloads, using the same atomic_publish machinery. A download
that fails its checksum now also leaves nothing behind.


We ran into this in amutable-systems/tine#292. We recently updated to a new buck which enabled the content-addressable buck-out/, and that exhibited the bug. Of course we shouldn't download a file three times in the first place (and I fixed that in amutable-systems/tine#295) but still, if it happens a buck build shouldn't crash on a half-written tar file.

Commit 19c7323 made the immediate materializer replace a write
action's output atomic. download_file has the same race and needs the
same mechanics.

Move that machinery out of the immediate materializer into
`buck2_execute`, where the download code can use it too.
A download with a declared checksum and size writes straight to its
content-based path, which has no configuration component. A target
analyzed under several configurations downloads that path once per
configuration, and each download removed what was there and wrote the
file in place. A consumer of the download that finished first could find
the file missing, empty or half written.

Commit 19c7323 fixed this kind of race for write actions. Do the same
for downloads, using the same `atomic_publish` machinery. A download
that fails its checksum now also leaves nothing behind.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 12, 2026
@meta-codesync

meta-codesync Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D124703713. (Because this pull request was imported automatically, there will not be any future comments.)

@cormacrelf

Copy link
Copy Markdown
Collaborator

@lf- another CBP race for your tally

@lf-

lf- commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

bloody hell. maybe i should dispatch an agent to write a tla+ formalization of what it's doing and then find all the bugs in it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants