Bug: Segmentation fault when using with confluent kafka consumer
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
研究方向
使用 KafkaContainer、confluent_kafka.Consumer、asyncio.to_thread 和 pytest-asyncio,從提供的 test_sample 重現開始。查看連結的 confluent-kafka issue,以了解相關背景,並記錄 Python、Docker、testcontainers-python 以及相依套件的版本。測試完成且 pytest 環境不再發生 segfault,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Describe the bug
Creating an asyncio test case that uses the kafka container on completion of the test (the test itself is successful) the pytest environment segfaults.
To Reproduce
Provide a self-contained code snippet that illustrates the bug or unexpected behavior. Ideally, send a Pull Request to illustrate with a test that illustrates the problem.
import asyncio
import time
import sys
from confluent_kafka import Consumer
import pytest
from testcontainers.core.waiting_utils import wait_for_logs
from testcontainers.kafka import KafkaContainer
@pytest.fixture(scope="module")
def kafka_container():
"""Provide a temporary Redis container."""
with KafkaContainer("mirror.gcr.io/confluentinc/cp-kafka:7.6.0") as container:
wait_for_logs(container, "Awaiting socket connections on 0.0.0.0:9093")
for topic in ["mytopic"]:
container.exec(
f"kafka-topics "
f"--bootstrap-server localhost:9092 "
f"--create "
f"--topic {topic} "
f"--partitions 3 "
f"--replication-factor 1",
)
yield container
async def kafka_consumer(consumer, timeout=1.0):
while True:
msg = await asyncio.to_thread(consumer.poll, timeout=timeout)
if msg is None:
continue
if msg.error():
print("Consumer error: {}".format(msg.error()))
continue
print('Received message: {}'.format(msg.value().decode('utf-8')))
async def main(consumer):
task = asyncio.create_task(kafka_consumer(consumer))
await asyncio.sleep(10)
print("Cancelling the task...")
task.cancel()
try:
await task
except asyncio.CancelledError:
print("Task was cancelled")
@pytest.mark.asyncio(loop_scope="function")
async def test_sample(kafka_container):
consumer = Consumer({
'bootstrap.servers': kafka_container.get_bootstrap_server(),
'group.id': 'mygroup',
'auto.offset.reset': 'earliest',
"debug":"all"})
consumer.subscribe(['mytopic'])
await main(consumer)
consumer.close()
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.
[project]
name = "kafka-test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"confluent-kafka>=2.9.0",
]
[dependency-groups]
dev = [
"pytest>=8.3.5",
"pytest-asyncio>=0.26.0",
"testcontainers>=4.10.0",
]
More info
https://github.com/confluentinc/confluent-kafka-python/issues/1953#issuecomment-2784234429
- 主要語言
- Python
- 星號
- 2.3k
- 分支
- 397
- 平均合併
- 8 天 16 小時
- 30 天內合併 PR
- 5
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
testcontainers/testcontainers-python 的其他 Issue
-
Feature: Stream bytes out on copy_from_container可能已有人在做 @archit15singh 於 11 天前認領。 未關閉🚀 enhancement
難度 2/5 1-3 小時 新手友好度 67/100
-
Bug: HttpWaitStrategy ignores response predicates for accepted HTTP error statuses可能已有人在做 @PranavMulakala 於 41 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 85/100
-
Bug: LogMessageWaitStrategy: a container that exits before its message raises without its logs, and __enter__ then removes the container可能已有人在做 @granzer69 於 42 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 67/100
testcontainers/testcontainers-python#1086 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
testcontainers/testcontainers-python#578 · 5 則留言 ·
查看 testcontainers/testcontainers-python 的全部 Issue
相似的 Issue
-
bug feature request
難度 2/5 1-3 小時 新手友好度 67/100
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 66/100
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
Qiskit/qiskit-obp#156 ·
-
action-item enhancement
難度 2/5 1-3 小時 新手友好度 88/100
getcommunityone/open-navigator#1658 ·
維護者通常 1 天內回覆
-
review-panel severity:low
難度 2/5 1-3 小時 新手友好度 72/100
kristovatlas/coin-accounting#636 ·
維護者通常 1 天內回覆