Bug: Segmentation fault when using with confluent kafka consumer
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 5
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信