testcontainers / testcontainers/testcontainers-python
Bug: Starting multiple containers at once in parallel causes Conflict by starting ryuk container multiple times due to race condition
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 2.3k
- フォーク
- 386
- 平均マージ
- 4時間 40分
- マージ済み PR(30日)
- 1
説明
Describe the bug
Starting two testcontainers at once triggers both of them to call Reaper._create_instance close in time. Both Reaper instances attempt to create the same ryuk container (since SESSION_ID is the same).
This is relevant when using pytest-parallel, which my organization does. I can probably work around the problem by serializing testcontainer start() calls on one thread.
To Reproduce
from testcontainers.postgres import PostgresContainer
import concurrent.futures
def start_postgres_container(port: int):
with PostgresContainer(port=port) as postgres:
print("Postgres is running on port", postgres.get_exposed_port(port))
with concurrent.futures.ThreadPoolExecutor() as executor:
future1 = executor.submit(start_postgres_container, port=5400)
# Uncommenting this reliably avoids the error
# import time
# time.sleep(5)
future2 = executor.submit(start_postgres_container, port=5401)
future1.result()
future2.result()
Runtime environment
Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.
# Get the operating system information (on a unix os).
$ uname -a
Darwin xxx 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020 arm64 arm Darwin
$ python --version
Python 3.11.10
$ docker info
# Get all python packages.
$ pip freeze
certifi==2024.8.30
charset-normalizer==3.4.0
docker==7.1.0
idna==3.10
requests==2.32.3
testcontainers==4.8.2
typing_extensions==4.12.2
urllib3==2.2.3
wrapt==1.17.0
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Reaper._create_instance から始め、issue にある concurrent.futures の再現を 2 つの PostgresContainer インスタンスで実行します。完了条件は、同時起動で ryuk コンテナを複数回作成しようとしても Conflict が発生しなくなり、両方のコンテナが正常に起動することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- docker, python
- 領域
- testing-qa
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100