Skip to content

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

Merged
shibd merged 4 commits into
apache:mainfrom
BewareMyPower:bewaremypower/fix-subscribe-timeout
Jun 29, 2023
Merged

Fix retriable errors not handled well when creating producer or consumer#293
shibd merged 4 commits into
apache:mainfrom
BewareMyPower:bewaremypower/fix-subscribe-timeout

Conversation

@BewareMyPower
Copy link
Copy Markdown
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
Comment thread lib/ConsumerImpl.cc
@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