Skip to content

Fix reader hanging when startMessageId is latest - #1364

Merged
shibd merged 4 commits into
apache:masterfrom
RobertIndie:fix-reader-hang
May 14, 2025
Merged

shibd merged 4 commits into
apache:masterfrom
RobertIndie:fix-reader-hang

Conversation

@RobertIndie

Copy link
Copy Markdown
Member

Motivation

The Go client version 0.15.0 introduced a regression bug. If the reader's startMessageId is set to the latest, it will hang while reading. This issue can be reproduced using the new test case: TestReaderReadFromLatest.

Modifications

The root cause is a change in behavior from before version 0.15.0. Previously, the consumer would avoid discarding messages if startMessageId was set to Latest. This logic was altered in this pull request: https://github.com/apache/pulsar-client-go/pull/1340/files#diff-782cf41d23c24657ede53da5d028f05819b302305ed676c61322b4cfba4265e9L1454-L1457

The following logic was removed:

// if we start at latest message, we should never discard
if pc.options.startMessageID != nil && pc.options.startMessageID.equal(latestMessageID) {
    return false
}

In version 0.15.0, if startMessageId is Latest, the reader won't receive any messages because all message IDs are before the latest and will be discarded. We need to reinstate this check.

For the seek operation, the correct approach is:

  • When handling a seek request, the consumer should set the seekMessageId before reconnecting.
  • After reconnecting, the consumer should check if seekMessageId exists. If it does, it indicates the consumer is seeking, and seekMessageId should be set as startMessageId. This ensures that even if the reader's startMessageId is Latest, it won't receive messages before the specified seek message ID, maintaining the correct behavior as intended in this PR.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / GoDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@RobertIndie RobertIndie self-assigned this May 12, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses a regression in the reader behavior when using a Latest startMessageID by reinstating a check that prevents discarding messages. The key changes include:

  • Adding a new test case (TestReaderReadFromLatest) to verify that messages are correctly received when starting from Latest.
  • Introducing a new field (seekMessageID) and modifying the seek logic in the partition consumer to correctly set the startMessageID after a seek.
  • Reinserting the check for Latest messages in the message discard function.

Reviewed Changes

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

File Description
pulsar/reader_test.go New test case added to verify behavior when starting from the latest ID.
pulsar/consumer_partition.go Updated seek logic and reintroduced check for Latest, with new field.

Comment thread pulsar/reader_test.go Resolved
Comment thread pulsar/consumer_partition.go Resolved
@shibd
shibd merged commit 2516598 into apache:master May 14, 2025
RobertIndie added a commit that referenced this pull request May 15, 2025
* Fix reader hanging when startMessageId is latest

* Fix lint

* Apply suggestions from code review

Co-authored-by: Copilot <[email protected]>

* Add comment to seekMessageId

---------

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit 2516598)
@RobertIndie RobertIndie added this to the v0.16.0 milestone Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants