testcontainers / testcontainers/testcontainers-python
Bug: Starting multiple containers at once in parallel causes Conflict by starting ryuk container multiple times due to race condition
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 2.3k
- Fork
- 386
- Merge trung bình
- 4 giờ 40 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với Reaper._create_instance và chạy bản tái hiện concurrent.futures từ issue bằng hai instance PostgresContainer. Hoàn tất có nghĩa là các lần khởi động đồng thời không còn tạo ra Conflict do cố gắng tạo container ryuk nhiều lần, đồng thời cả hai container đều khởi động thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- docker, python
- Lĩnh vực
- testing-qa
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100