Skip to content

🐛 fix(provision): serialize concurrent provisioning#3756

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:fix-concurrent-provision-clobber-2515
Feb 18, 2026
Merged

🐛 fix(provision): serialize concurrent provisioning#3756
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:fix-concurrent-provision-clobber-2515

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

When multiple tox processes run concurrently and provisioning is required (via requires), they all attempt to create and populate the same .tox/.tox provision environment without any coordination. 🔒 One process can delete or overwrite virtualenv files while another is actively importing from them, causing ModuleNotFoundError crashes like missing pip._vendor modules.

The provision environment is a RunToxEnv, which unlike PackageToxEnv has no file-based locking. Rather than adding locking to all RunToxEnv instances, wrapping just the run_provision lifecycle with a FileLock on {env_dir}/file.lock follows the existing pattern already used by packaging environments. The lock covers setup through execution so a second process waits until the first finishes before attempting its own provisioned run.

This uses the same file.lock convention that _clean() already preserves via ensure_empty_dir(env_dir, except_filename="file.lock"), so the lock file survives environment recreation.

Fixes #2515

Multiple tox processes running simultaneously would corrupt the shared
provision environment (.tox/.tox) because setup and execution had no
cross-process coordination. One process could delete or modify the
virtualenv while another was actively using it, causing import errors
like missing pip modules.

Wrapping the provision lifecycle with a FileLock follows the same
pattern already used by PackageToxEnv for package environments. The
lock covers setup through execution to prevent a concurrent process
from cleaning and recreating the env mid-run.
@gaborbernat gaborbernat added the bug:normal affects many people or has quite an impact label Feb 18, 2026
@gaborbernat gaborbernat enabled auto-merge (squash) February 18, 2026 14:51
@gaborbernat gaborbernat merged commit 0edc50a into tox-dev:main Feb 18, 2026
52 of 53 checks passed
@gaborbernat gaborbernat deleted the fix-concurrent-provision-clobber-2515 branch February 20, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided bug:normal affects many people or has quite an impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multiple tox instances will clobber the .tox directory when provision_tox_env is used

1 participant