From e61985dbe52973df8a40c710978c36caff21b037 Mon Sep 17 00:00:00 2001 From: John Sirois Date: Tue, 20 Sep 2022 16:16:17 -0700 Subject: [PATCH] Fix venv re-population race. (Cherry-pick of #16931) There was a race in venv re-population due to a non-atomic `rm`, create sequence. There was no real need for the `rm` and the create is atomic on its own; so just remove the `rm` which was only attempting to guard "corrupted" venvs in a slapdash way. Now the venv either exists or it doesn't from the script point of view. If the venv exists but has been tampered with, its execution will consistently fail until there is a manual intervention removing the venv dir offline. Fixes #14618 Fixes #16778 (cherry picked from commit cace8518a43646ac0e84c4f841cee01e46b1defc) --- src/python/pants/backend/python/util_rules/pex.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/python/pants/backend/python/util_rules/pex.py b/src/python/pants/backend/python/util_rules/pex.py index 901a413f5c2..c13b0e029a5 100644 --- a/src/python/pants/backend/python/util_rules/pex.py +++ b/src/python/pants/backend/python/util_rules/pex.py @@ -696,8 +696,7 @@ def _create_venv_script( # If the seeded venv has been removed from the PEX_ROOT, we re-seed from the original # `--venv` mode PEX file. - if [ ! -e "${{target_venv_executable}}" ]; then - rm -rf "${{venv_dir}}" || true + if [ ! -e "${{venv_dir}}" ]; then PEX_INTERPRETER=1 ${{execute_pex_args}} -c '' fi