Skip to content

[Bug] Subscription is deleted unexpectedly #17572

Closed

Description

@dragonls

Search before asking

  • I searched in the issues and found nothing similar.

Version

2.8.3

Minimal reproduce step

Set up a Pulsar cluster and set the broker to enable subscription expiry check (subscriptionExpirationTimeMinutes>0).

  1. Having a topic persistent://test/test/test with durable subscription sub-test, running on broker A. The consumer of subscription sub-test should run stably longer than subscriptionExpirationTimeMinutes.
  2. Make broker A stuck, such as gdb attach <broke A pid>, and then kill -9 <consumer pid>; kill -9 <broke A pid>. The main purpose is to prevent the broker from exiting normally and prevent the consumer from reconnecting to new broker ASAP.
  3. The topic persistent://test/test/test will be owned by another broker X, and recover the cursor of subscription sub-test with lastActive time, which mostly is the start time of previous consumer.
  4. The broker X will do subscription expiry check in subscriptionExpiryCheckIntervalInMinutes and then delete subscription sub-test of topic persistent://test/test/test.

What did you expect to see?

The new broker should not delete subscription sub-test of topic persistent://test/test/test, because it is still active just before broker A stopped.
The new broker should recover the cursor of subscription sub-test with lastActive time correctly, which should be the real last active time of the consumer, such as just the time before consumer stopped.

What did you see instead?

Subscription sub-test of topic persistent://test/test/test is deleted unexpectedly.

Anything else?

This bug mostly happened while there are brokers shutdown with OOM or other situation, which make the broker not shutdown gracefully. And the new broker load the topics and then do subscription expiry check soon before consumer reconnected, then the subscription may be deleted unexpectedly.

The broker use sub.cursor.getLastActive() to do subscription expiry check.

if (System.currentTimeMillis() - sub.cursor.getLastActive() > expirationTimeMillis) {
sub.delete().thenAccept(v -> log.info("[{}][{}] The subscription was deleted due to expiration",
topic, subName));
}

The lastActive in ManagedCursorImpl only be updated in 3 places:

  • org.apache.pulsar.broker.service.persistent.PersistentSubscription#addConsumer
  • org.apache.pulsar.broker.service.persistent.PersistentSubscription#removeConsumer
  • org.apache.bookkeeper.mledger.impl.ManagedCursorImpl#internalResetCursor

So it will be be updated during stable consumption.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/bug
    on Sep 9, 2022
  2. dragonls commented on Sep 9, 2022

    @dragonls
    ContributorAuthor

    Updating lastActive in ManagedCursorImpl during stable consumption can fix this bug.

    Fox example, add cursor.updateLastActive() in org.apache.pulsar.broker.service.persistent.PersistentSubscription#acknowledgeMessage, but I am not sure whether this is the right place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions