Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition with forked monorepos #9723

Merged
merged 3 commits into from
Oct 14, 2024

Conversation

TheSven73
Copy link
Contributor

@TheSven73 TheSven73 commented Sep 29, 2024

There is a race condition when installing packages from multiple forked monorepos. Fix it.

See discussion

@TheSven73
Copy link
Contributor Author

Not sure how to add reviewers / watchers. @radoering @gustavgransbo @seeker25

Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍
Just some minor nitpicks.

tests/installation/test_executor.py Outdated Show resolved Hide resolved
src/poetry/installation/executor.py Show resolved Hide resolved
src/poetry/installation/executor.py Show resolved Hide resolved
When installing packages from different directories of a forked
monorepo, a race condition may occur, where multiple git clients
are interacting in parallel with the same git repository.

Add a failing test to detect the race condition. Mark as xfail.
This test succeeds due to a problem with the poetry test framework.

Example pyproject.toml which triggers the problem:
```toml
[tool.poetry]
name = "some_other_repo"
version = "0.1.0"
description = ""
authors = ["Jonathan Rayner <jonathan.j.rayner@gmail.com>"]
packages = [{ include = "some_other_repo"}]

[tool.poetry.dependencies]
python = "^3.10 <3.13"

pkg_1 = {git = "git@github.com:JonathanRayner/some_monorepo.git", subdirectory = "pkg_1" }
pkg_2 = {git = "git@github.com:gustavgransbo/some_monorepo.git", subdirectory = "pkg_2", tag="v2"}

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
```
Source: @gustavgransbo
https://github.com/orgs/python-poetry/discussions/9718#discussioncomment-10785589
@TheSven73 TheSven73 marked this pull request as ready for review October 13, 2024 18:25
@TheSven73 TheSven73 changed the title WIP: Fix race condition with forked monorepos Fix race condition with forked monorepos Oct 13, 2024
When git clones a repo in a base directory, it will place the clone
in a subdirectory of the base. That subdirectory is named after
the repo url name, which is the "testing" right before the .git in
https://github.com/test/testing.git

This behaviour may introduce race conditions to Poetry. Let the
mock repo mimic it, so that the (absence of) race conditions
can be verified.
When installing packages from different directories of a forked
monorepo, a race condition may occur, where multiple git clients
are interacting in parallel with the same git repository.

Fix by serializing git operations that interact with the same
git repository.

This makes the test succeed. Remove xfail.

Links:
python-poetry#9658 (comment)
https://github.com/orgs/python-poetry/discussions/9718#discussioncomment-10785589
@radoering radoering merged commit a9793c9 into python-poetry:main Oct 14, 2024
87 checks passed
@TheSven73 TheSven73 deleted the concurrent-forked-repos-fix branch October 14, 2024 15:59
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants