-
-
Notifications
You must be signed in to change notification settings - Fork 693
fix: Handle symbolic linking race condition #3796
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
base: release/1.9
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -153,7 +153,7 @@ if [[ "$IS_ZIPFILE" == "1" ]]; then | |||||
| fi | ||||||
| # The bin/ directory may not exist if it is empty. | ||||||
| mkdir -p "$(dirname $python_exe)" | ||||||
| ln -s "$symlink_to" "$python_exe" | ||||||
| ln -sfn "$symlink_to" "$python_exe" | ||||||
| elif [[ "$RECREATE_VENV_AT_RUNTIME" == "1" ]]; then | ||||||
| if [[ -n "$RULES_PYTHON_EXTRACT_ROOT" ]]; then | ||||||
| use_exec=1 | ||||||
|
|
@@ -226,16 +226,16 @@ EOF | |||||
| fi | ||||||
|
|
||||||
| mkdir -p "$venv/bin" | ||||||
| ln -s "$python_exe_actual" "$python_exe" | ||||||
| ln -sfn "$python_exe_actual" "$python_exe" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above,
Suggested change
|
||||||
|
|
||||||
| if [[ ! -e "$venv_site_packages" ]]; then | ||||||
| mkdir -p $(dirname $venv_site_packages) | ||||||
| ln -s "$runfiles_venv_site_packages" "$venv_site_packages" | ||||||
| ln -sfn "$runfiles_venv_site_packages" "$venv_site_packages" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| fi | ||||||
| fi | ||||||
|
|
||||||
| if [[ ! -e "$venv/pyvenv.cfg" ]]; then | ||||||
| ln -s "$runfiles_venv/pyvenv.cfg" "$venv/pyvenv.cfg" | ||||||
| ln -sfn "$runfiles_venv/pyvenv.cfg" "$venv/pyvenv.cfg" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @scasagrande, what about using the suggested approach? Because this just fails back if we cannot create the symlink. We also ensure that the existing file is a symlink with the AI proposed approach. Could you please explain the usage of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can take a closer look because I would want to better understand it. But at the same time if no one else has had this problem, and I no longer have a problem, is there actually a problem that we're solving? Either way if you prefer it I'll test it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
no, |
||||||
| fi | ||||||
| else | ||||||
| use_exec=1 | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
ln -sfnis not atomic and can introduce a different race condition.\n\nUnder the hood,ln -sfperforms anunlink()followed by asymlink(). If multiple processes run this bootstrap script concurrently, one process might delete the symlink created by another process, leading to a transient window where the symlink does not exist. Any concurrent process attempting to execute or read the file during this window will fail with aNo such file or directoryerror. Additionally, the-nflag is not standard POSIX and may behave differently or be unsupported on some platforms.\n\nA safer, fully atomic approach that avoids deleting existing symlinks is to attempt the creation withln -sand fallback to verifying the symlink's existence if it fails due to already existing:\n\nbash\nln -s \"$symlink_to\" \"$python_exe\" 2>/dev/null || [[ -L \"$python_exe\" ]]\n\n\nSincesymlink()is an atomic system call, this guarantees that the symlink is either created successfully or already exists, without ever unlinking it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotta love seeing
\n\nin a comment