Skip to content

Fix #422: Add per-version locking to prevent concurrent install races#471

Merged
Zordrak merged 1 commit intomasterfrom
fix/422-concurrent-install-locking
Apr 24, 2026
Merged

Fix #422: Add per-version locking to prevent concurrent install races#471
Zordrak merged 1 commit intomasterfrom
fix/422-concurrent-install-locking

Conversation

@Zordrak
Copy link
Copy Markdown
Collaborator

@Zordrak Zordrak commented Apr 24, 2026

Fix #422

When TFENV_AUTO_INSTALL triggers from multiple parallel terraform commands (e.g. terraform plan in CI), two processes could try to install the same version simultaneously, causing corrupted installs from concurrent unzip operations.

This adds a portable file-based lock (using mkdir atomicity) that serializes installs of the same version:

  • Per-version lock — different versions can still install in parallel
  • Portablemkdir is atomic on all POSIX systems (Linux, macOS, Windows/MSYS)
  • Wait with detection — waits up to 60 seconds, checking each second if the other process completed the install
  • Early exit — if the version appears while waiting, exits cleanly
  • Stale lock recovery — after timeout, removes the stale lock (covers killed processes) and retries
  • Clean release — lock is released via trap on EXIT, INT, and TERM

Lock files are created at ${TFENV_CONFIG_DIR}/.install-lock-${version} (directories, not files, since mkdir is the atomic primitive).

@Zordrak Zordrak force-pushed the fix/422-concurrent-install-locking branch from 3a489db to 14124ca Compare April 24, 2026 12:51
When TFENV_AUTO_INSTALL triggers from multiple parallel terraform
commands (e.g. terraform plan in CI), two processes could try to
install the same version simultaneously, causing corrupted installs.

This adds a portable file-based lock (using mkdir atomicity) that
serializes installs of the same version:

- Lock is per-version so different versions can install in parallel
- Uses mkdir which is atomic on all POSIX systems (Linux, macOS, MSYS)
- Waits up to 60 seconds for a concurrent install to finish
- If the version appears while waiting, exits cleanly (other process won)
- Stale lock detection after timeout (covers killed processes)
- Lock is released via trap on EXIT, INT, and TERM
@Zordrak Zordrak force-pushed the fix/422-concurrent-install-locking branch from 14124ca to 52e3a38 Compare April 24, 2026 13:21
@Zordrak Zordrak merged commit aa1be27 into master Apr 24, 2026
5 checks passed
@Zordrak Zordrak deleted the fix/422-concurrent-install-locking branch April 24, 2026 15:11
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.

Concurrent Installation Issue with TFENV_AUTO_INSTALL in Terragrunt Environments repository

1 participant