Skip to content

Conversation

@Ankith-Confluent
Copy link
Member

@Ankith-Confluent Ankith-Confluent commented Oct 6, 2025

Summary

This PR fixes a bug in rd_kafka_consume_batch() where EOF messages incorrectly advance the consumer position by 2 instead of 1 when enable.partition.eof=true. The bug causes rd_kafka_position() to return last_offset + 2 instead of the correct last_offset + 1 after consuming an EOF message in batch mode.

Motivation

Root Cause

In src/rdkafka_queue.c, the rd_kafka_q_serve_rkmessages() function updates the consumer position for all messages in a batch, including EOF messages. EOF messages have error code RD_KAFKA_RESP_ERR__PARTITION_EOF but are not control messages, so they were incorrectly incrementing the offset.

Changes

  1. File: src/rdkafka_queue.c
    Added a check to prevent EOF messages from updating the consumer position.

  2. Regression subtest: tests/0137-barrier_batch_consume.c
    New Subtest do_test_consume_batch_eof_position() is added

Test Flow

  1. Produces 5 messages to a test topic
  2. Consumes messages using rd_kafka_consume_batch_queue() with
    enable.partition.eof=true
  3. Receives EOF message after consuming all real messages
  4. Verifies rd_kafka_position() returns last_offset + 1 (not last_offset + 2)

@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

…h_queue

This commit introduces a new test, do_test_consume_batch_eof_position, to verify that the consumer position is correctly updated when EOF messages are received with enable.partition.eof set to true. The test ensures that the consumer position advances by 1 instead of 2, addressing a previously identified bug. The test includes setup for producing messages, consuming them, and validating the final consumer position after EOF is reached.
@Ankith-Confluent Ankith-Confluent marked this pull request as ready for review October 7, 2025 08:22
@Ankith-Confluent Ankith-Confluent requested a review from a team as a code owner October 7, 2025 08:22
Copilot AI review requested due to automatic review settings October 7, 2025 08:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in rd_kafka_consume_batch() where EOF messages incorrectly advance the consumer position by 2 instead of 1 when enable.partition.eof=true, causing rd_kafka_position() to return an incorrect offset.

  • Added a check to prevent EOF messages from updating consumer position in rd_kafka_q_serve_rkmessages()
  • Added comprehensive regression test to verify correct consumer position after EOF messages

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/rdkafka_queue.c Fixed offset advancement logic to exclude EOF messages from position updates
tests/0137-barrier_batch_consume.c Added regression test to verify EOF message position handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

This commit modifies the comment in the do_test_consume_batch_eof_position function to clarify that the position value is being extracted from the partition list after reaching EOF. This change enhances code readability and understanding of the test's purpose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant