feat: add git concurrency patch - #2180
Open
sofisl wants to merge 6 commits into
Open
Conversation
This was referenced Aug 6, 2026
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.
Description
This PR introduces an fcntl.flock file lock around the git clone, git checkout, and git pull operations within synthtool.sources.git.clone.
Context & Motivation: As part of the transition away from using Docker for librarian generate on Python packages (via the removal of librarian.yaml), client library generation is now executed locally on the host machine.
When running librarian generate -v --all, generation tasks are executed concurrently across multiple packages. This concurrency introduces a race condition where multiple processes attempt to clone or pull the same shared repository in the synthtool cache simultaneously, resulting in git index.lock collision errors that fail the generation.
By applying an exclusive file lock (.lock) over the specific cache repository before manipulating it, we guarantee that concurrent librarian processes serialize their git operations safely and avoid index.lock collisions.
Changes Made
Added an fcntl.flock block in synthtool/sources/git.py that surrounds the git clone, git checkout, and git pull subprocess calls.
Added testCloneConcurrencyPatch to tests/test_git.py using mock.patch to verify that the LOCK_EX and LOCK_UN calls are correctly executed during cloning.
Corrected the indentation block for the try/finally block to ensure synthtool parses it properly.