Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Transactional producer's sender loops on AttributeError after a fatal error (2.2 and 2.3 branches)

Đang mở Phù hợp với người mới
#3,161 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
distributed-systems

Hướng nghiên cứu

Bắt đầu từ Sender.run_once trong kafka/producer/sender.py, nơi _maybe_abort_batches gọi self._accumulator.abort_batches(exc), sau đó kiểm tra kafka/producer/record_accumulator.py, nơi trên các nhánh này chỉ định nghĩa _abort_batches. Xác nhận sự không khớp bằng cách tái hiện với hai producer giao dịch dùng chung một transactional_id trên một broker. Hoàn thành khi lỗi nghiêm trọng lan truyền ra khỏi commit_transaction(), thay vì luồng I/O ghi log AttributeError rồi lặp lại. Trước tiên, hãy xác nhận maintainer chấp nhận backport lên các nhánh 2.2 và 2.3.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

On the 2.2 and 2.3 branches (seen on 2.2.15, and still there in 2.2.20, 2.3.2 and the current heads of both), once a transactional producer hits a fatal error the sender thread loops forever, so commit_transaction() never returns.

Sender.run_once calls _maybe_abort_batches(last_error) when the transaction manager has a fatal error, which calls self._accumulator.abort_batches(exc) (sender.py:335 on 2.2, :343 on 2.3), but RecordAccumulator on those branches only has _abort_batches (record_accumulator.py:623 on 2.2, :473 on 2.3). So it raises AttributeError, the I/O thread catches and logs it, and goes round again:

ERROR:kafka.producer.sender:<Sender client_id=kafka-python-producer-2 transactional_id=pytx-producer>: Aborting producer batches due to fatal error: [Error 47] InvalidProducerEpochError
ERROR:kafka.producer.sender:<Sender client_id=kafka-python-producer-2 transactional_id=pytx-producer>: Uncaught error in kafka producer I/O thread
...
AttributeError: 'RecordAccumulator' object has no attribute 'abort_batches'. Did you mean: '_abort_batches'?

It seems master fixed this as part of #3010 (which renamed _abort_batches to abort_batches), so 3.0.x is fine, but the rename never made it back to 2.2 or 2.3.

To reproduce, fence a transactional producer by starting a second one with the same transactional_id, then use the first one again:

from kafka import KafkaProducer

first = KafkaProducer(bootstrap_servers=bootstrap, transactional_id="tx")
first.init_transactions()

second = KafkaProducer(bootstrap_servers=bootstrap, transactional_id="tx")
second.init_transactions()

first.begin_transaction()
first.send("topic", value=b"zombie")
first.commit_transaction()  # never returns; the log fills with the AttributeError above

I'd expect commit_transaction() to raise the fatal error (InvalidProducerEpochError here, from AddPartitionsToTxn) instead. I hit this testing a Kafka-protocol gateway against kafka-python 2.2.15, where it's easy to work around, but hopefully a backport of the one-line rename (or a call to _abort_batches in sender.py) to 2.2 and 2.3 is simple enough. I'm happy to open PRs against both branches if that helps.

Ngôn ngữ chính
Python
Star
5.9k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dpkp/kafka-python

Tất cả issue của dpkp/kafka-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.