Skip to content

Fix retriable errors not handled well when creating producer or consumer #293

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

Merged
merged 4 commits into from
Jun 29, 2023

Conversation

BewareMyPower
Copy link
Contributor

Fixes #292

Motivation

When a consumer failed to subscribe due to a retriable error, the time point comparation is wrong:

if (isRetriableError(result) && (creationTimestamp_ + operationTimeut_ < TimeUtils::now())) {

creationTimestamp_ + operationTimeut_ is the deadline, TimeUtils::now() is the current time, we should use > instead of < here to compare them. Otherwise, if the consumer encountered a retriable error and the deadline is not exceeded, the consumer won't reconnect and fail with ResultRetryable.

Modifications

Reverse the comparation between the deadline and the current time. When it times out, completing the future with ResultTimeout instead of the result itself, which is always ResultRetryable.

Add ConsumerTest.testRetrySubscribe to verify this change.

TODO

Support configuring the operation timeout in milliseconds.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

Fixes apache#292

### Motivation

When a consumer failed to subscribe due to a retriable error, the time
point comparation is wrong:

https://github.com/apache/pulsar-client-cpp/blob/633f4bbe8c182128da09803172676b9d6af05057/lib/ConsumerImpl.cc#L321

`creationTimestamp_ + operationTimeut_` is the deadline,
`TimeUtils::now()` is the current time, we should use `>` instead of `<`
here to compare them. Otherwise, if the consumer encountered a retriable
error and the deadline is not exceeded, the consumer won't reconnect and
fail with `ResultRetryable`.

### Modifications

Reverse the comparation between the deadline and the current time. When
it times out, completing the future with `ResultTimeout` instead of the
`result` itself, which is always `ResultRetryable`.

Add `ConsumerTest.testRetrySubscribe` to verify this change.

### TODO

Support configuring the operation timeout in milliseconds.
@BewareMyPower BewareMyPower added the bug Something isn't working label Jun 27, 2023
@BewareMyPower BewareMyPower added this to the 3.3.0 milestone Jun 27, 2023
@BewareMyPower BewareMyPower self-assigned this Jun 27, 2023
@BewareMyPower BewareMyPower changed the title Fix retriable errors not handled well when subscribing Fix retriable errors not handled well when creating producer or consumer Jun 28, 2023
@shibd shibd merged commit 94cf3fc into apache:main Jun 29, 2023
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-subscribe-timeout branch June 29, 2023 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Race condition when closing during seek
2 participants