Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make +CARGO output copy atomic #61

Merged
merged 3 commits into from
Jun 6, 2024
Merged

Conversation

idelvall
Copy link
Member

@idelvall idelvall commented Jun 5, 2024

Concurrent builds of the same target may use the output of the other, since the cache lock is released between the cargo build and the output copy.
This PR fixes that

@idelvall idelvall requested a review from a team as a code owner June 5, 2024 11:31
@@ -60,10 +63,9 @@ CARGO:
set -e; \
cargo $args; \
cargo sweep -r -t $EARTHLY_SWEEP_DAYS; \
cargo sweep -r -i;
IF [ "$output" != "" ]
DO +COPY_OUTPUT --output=$output
Copy link
Member Author

Choose a reason for hiding this comment

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

Running this outside of the previous RUN command was the culprit

ENV EARTHLY_FUNCTIONS_HOME="/tmp/earthly/functions"
RUN mkdir -p $EARTHLY_FUNCTIONS_HOME
RUN if [ ! -f $EARTHLY_FUNCTIONS_HOME/copy-output.sh ]; then \
OUTPUT_TMP_FOLDER="/tmp/earthly/lib/rust"; \

Choose a reason for hiding this comment

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

Thanks Nacho for quick fix. I think there is a race here:

Let's say there are two jobs A and B running parallel producing output.
A completes first by holding the cargo cache mount point and it copies the output to /tmp/earthly/lib/rust
And then B starts even before A run or completes rename-output.sh at line 69.
Now, B also starts copying its output to /tmp/earthly/lib/rust since the tmp folder is not in lock IIUC

But at the end of A running script rename-output.sh, it will delete the tmp folder /tmp/earthly/lib/rust along with B's artifacts.

IOW, using same temp folder /tmp/earthly/lib/rust without lock for multiple jobs, feels like a race to me.
I think we might use mktemp -d etc to create unique temp dir for each job outputs

Please let me know if i miss something

Copy link
Member Author

@idelvall idelvall Jun 6, 2024

Choose a reason for hiding this comment

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

I think you are missing this part: /tmp/earthly/lib is not shared between builds (it's in the layers fs).
The only shared paths (belonging to a shared cache) are:

  • /tmp/earthly/.cargo
  • ./target

Copy link
Member Author

Choose a reason for hiding this comment

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

so, rename-output.sh just changes the location of the files, in the layers filesystem. I will add some comments to make this clearer

Choose a reason for hiding this comment

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

Yeah that makes sense. Thanks

@idelvall idelvall merged commit a49d2a0 into main Jun 6, 2024
2 checks passed
@idelvall idelvall deleted the nacho/rust-atomic-output_copy branch June 6, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants