Skip to content

Conversation

@sushain97
Copy link
Contributor

When two instances of Bazelisk are running concurrently and downloading Bazel, the current code admits a race. This patch fixes the issue by using randomly named files for temporary paths.

For example:

{"error":"could not download Bazel: failed to download bazel: failed to move /root/.bazel_binaries/stripe-bazel/downloads/sha256/09bac5c11165a6ab0b7a90d6937c8bc3fcdcda662ffe0590e87ac2ae0e5e8978/bin/bazel.tmp to /root/.bazel_binaries/stripe-bazel/downloads/sha256/09bac5c11165a6ab0b7a90d6937c8bc3fcdcda662ffe0590e87ac2ae0e5e8978/bin/bazel: rename /root/.bazel_binaries/stripe-bazel/downloads/sha256/09bac5c11165a6ab0b7a90d6937c8bc3fcdcda662ffe0590e87ac2ae0e5e8978/bin/bazel.tmp /root/.bazel_binaries/stripe-bazel/downloads/sha256/09bac5c11165a6ab0b7a90d6937c8bc3fcdcda662ffe0590e87ac2ae0e5e8978/bin/bazel: no such file or directory"}

if err != nil {
return fmt.Errorf("failed to create temporary file in %s: %w", parent, err)
}
defer os.Remove(tmpFile.Name())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a no-op unless the write fails and the rename never happens.

@meteorcloudy meteorcloudy requested a review from fweikert October 1, 2024 14:59
@sushain97
Copy link
Contributor Author

@fweikert 👋 anything I can help with to get this PR merged?

@fweikert
Copy link
Member

fweikert commented Oct 9, 2024

Thank you!

@fweikert fweikert merged commit 2f239be into bazelbuild:master Oct 9, 2024
@sushain97
Copy link
Contributor Author

Hi, when should we expect a release with this change?

@fweikert
Copy link
Member

Hi, when should we expect a release with this change?

https://github.com/bazelbuild/bazelisk/releases/tag/v1.22.1

@sushain97
Copy link
Contributor Author

Thanks!

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.

3 participants