forked from apache/pulsar-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix race condition of hasMessageAvailable by reading latest startMess…
…ageId each time ### Motivation See apache/pulsar-client-python#199 There is a race condition when `hasMessageAvailable` is called after `seek` if the start message ID of `Reader` is earliest. In `ConsumerImpl::hasMessageAvailableAsync`, if the connection is not established at the moment, `lastDequedMessageId_` will be `earliest` because no message is received. Since `lastMessageIdInBroker_` is also `earliest`, `getLastMessageIdAsync` will be called and then it comes at https://github.com/apache/pulsar-client-cpp/blob/e2cacb7dfb57b6d059b49fead2e1611548ff89b0/lib/ConsumerImpl.cc#L1554 However, before `getLastMessageIdAsync` is called, `messageId` was `earliest` because `lastDequedMessageId_` and `startMessageId_` were both `earliest`. However, when the callback is called, the `startMessageId_` has already been updated to `latest` in `connectionOpened`, so we should compare to `latest`. ### Modifications In the callback of `getLastMessageIdAsync`, retrieve the latest value of `startMessageId_` to compare rather then reusing the old value. Refactor the seek flow to reset the seek states and trigger the callback after updating the `startMessageId_`. `ReaderTest.testHasMessageAvailableAfterSeekToEnd` is added to cover the changes.
- Loading branch information
1 parent
747c186
commit e6e0adc
Showing
4 changed files
with
232 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.