Skip to content

[Bug][client] Multi-topic consumer send flow permits to broker before subscribing completes, leading to possible cascading failures #25005

Closed

Description

@lhotari

Search before reporting

  • I searched in the issues and found nothing similar.

Read release policy

  • I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

User environment

Issue was introduced in #14566, already in 2.10.5

Issue Description

Before the #14566 change, the client would first subscribe to all topics and then send flow permits to the broker in the startReceivingMessages method.
The behavioral change after #14566 is that messages will start flowing from the broker to the client immediately. If subscribing to any of the partitions fails, it will add a lot of extra work to the system and could cause cascading failures when brokers are at their limits. It's better to fix this problem and remove the newConsumer.resume(); lines added in this PR.

Error messages


Reproducing the issue

TBD

Additional information

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/bug
    on Nov 21, 2025
  2. changed the title [-][Bug][client] Multi-topic consumer send flow permits to broker before subscribing completes leading to possible cascading failures[/-] [+][Bug][client] Multi-topic consumer send flow permits to broker before subscribing completes, leading to possible cascading failures[/+] on Nov 21, 2025
  3. lhotari commented on Nov 21, 2025

    @lhotari
    MemberAuthor

    In scenarios where a lot of clients loose connectivity at once, the change made in #14566 will amplify the load on the brokers suddenly and a low amount of clients would be able to successfully connect to brokers before the subscribing times out. The clients would then retry and this loop adds a lot of unnecessary load.

  4. self-assigned this
    on Nov 21, 2025
  5. lhotari commented on Nov 21, 2025

    @lhotari
    MemberAuthor

    The newConsumer.resume() calls won't impact the behavior in all cases. This logic makes it not effective:

    // if the consumer is not partitioned or is re-connected and is partitioned, we send the flow
    // command to receive messages.
    if (!(firstTimeConnect && hasParentConsumer) && getCurrentReceiverQueueSize() != 0) {
    increaseAvailablePermits(cnx, getCurrentReceiverQueueSize());
    }

    The permits will be sent here:

    private void startReceivingMessages(List<ConsumerImpl<T>> newConsumers) {
    if (log.isDebugEnabled()) {
    log.debug("[{}] startReceivingMessages for {} new consumers in topics consumer, state: {}",
    topic, newConsumers.size(), getState());
    }
    if (getState() == State.Ready) {
    newConsumers.forEach(consumer -> {
    consumer.increaseAvailablePermits(consumer.getConnectionHandler().cnx(),
    consumer.getCurrentReceiverQueueSize());
    internalPinnedExecutor.execute(() -> receiveMessageFromConsumer(consumer, true));
    });
    }
    }

    However, there's another potential race condition here here. If the connection breaks when the call is made and reconnects immediately, it's possible that the consumer is left in a state where it won't have permits. I think I've seen a few cases like that over the years.

  6. lhotari commented on Nov 21, 2025

    @lhotari
    MemberAuthor

    Closing as not a bug.

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

Metadata

Metadata

Assignees

Labels

type/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions