Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Reader.HasNext() in Go client #3764

Merged
merged 3 commits into from
Mar 8, 2019

Conversation

merlimat
Copy link
Contributor

@merlimat merlimat commented Mar 6, 2019

Motivation

In Go client, the Reader.HasNext() is currently broken because it returns "true" when there are no more messages to read.

The issue is in the C++ Consumer::hasMessageAvailable(), combined with the use of message listener. The lastDequedMessage is being updated only after the listener is triggered, therefore an app checking hasMessageAvailable() from the listener thread will always be 1 message behind.

Since Go client wrapper, uses the listener internally, it is affected by this problem and it looks like a race condition with the lastDequedMessage being updated in a background thread.

@merlimat merlimat added type/bug The PR fixed a bug or issue reported a bug component/c++ labels Mar 6, 2019
@merlimat merlimat added this to the 2.3.1 milestone Mar 6, 2019
@merlimat merlimat self-assigned this Mar 6, 2019
@@ -1039,8 +1040,7 @@ void ConsumerImpl::hasMessageAvailableAsync(HasMessageAvailableCallback callback
return;
}

BrokerGetLastMessageIdCallback callback1 = [this, lastDequed, callback](Result result,
MessageId messageId) {
getLastMessageIdAsync([this, lastDequed, callback](Result result, MessageId messageId) {
if (result == ResultOk) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you refactor it to

const auto ret = (result == ResultOk && messageId > lastDequed && messageId.entryId() != -1);
callback(result, ret);

or even not use ret.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that this would improve readability


client, err := NewClient(ClientOptions{
URL: "pulsar://localhost:6650",
//Logger: func(level logutil.LoggerLevel, file string, line int, message string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to checkin with these comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.. :) removing these

@wolfstudy
Copy link
Member

LGTM

@merlimat
Copy link
Contributor Author

merlimat commented Mar 7, 2019

run java8 tests
run integration tests

@merlimat merlimat merged commit 593db1c into apache:master Mar 8, 2019
merlimat added a commit that referenced this pull request Mar 29, 2019
* Fixed Reader.HasNext() in Go client

* Fixed formatting

* Removed commented code
@merlimat merlimat deleted the fix-go-reader-has-next branch April 1, 2019 17:47
@merlimat
Copy link
Contributor Author

merlimat commented Apr 1, 2019

Merged in 2.3.1 at
36362ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants