Skip to content

feat: add git concurrency patch - #2180

Open
sofisl wants to merge 6 commits into
masterfrom
add-git-concurrency-patch
Open

feat: add git concurrency patch#2180
sofisl wants to merge 6 commits into
masterfrom
add-git-concurrency-patch

Conversation

@sofisl

@sofisl sofisl commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

@sofisl
sofisl requested review from a team as code owners August 6, 2026 22:18
Comment thread synthtool/sources/git.py Outdated
Comment thread synthtool/sources/git.py Outdated
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.

2 participants