Fix #422: Add per-version locking to prevent concurrent install races#471
Merged
Fix #422: Add per-version locking to prevent concurrent install races#471
Conversation
3a489db to
14124ca
Compare
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
14124ca to
52e3a38
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #422
When
TFENV_AUTO_INSTALLtriggers from multiple parallel terraform commands (e.g.terraform planin 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
mkdiratomicity) that serializes installs of the same version:mkdiris atomic on all POSIX systems (Linux, macOS, Windows/MSYS)trapon EXIT, INT, and TERMLock files are created at
${TFENV_CONFIG_DIR}/.install-lock-${version}(directories, not files, since mkdir is the atomic primitive).