Skip to content

[Bug][client] Multi-topic consumer with a message listener loses flow permits when redelivery clears its incoming queue #27016

Open

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 reproduced the issue on the master branch.

User environment

Issue Description

When a multi-topic or partitioned consumer has a message listener, the child ConsumerImpl instances are created with parentConsumerHasListener=true. When a message moves from a child's queue to the parent's queue, ConsumerImpl.messageProcessed() doesn't give the flow permit back. The parent gives it back later, in ConsumerBase.callMessageListener(), through receivedConsumer.increaseAvailablePermits(...), just before the listener runs.

The permit therefore goes back only if the message reaches callMessageListener(). If the parent removes the message from its own queue first, the permit is lost:

  • MultiTopicsConsumerImpl.redeliverUnacknowledgedMessages() calls consumer.redeliverUnacknowledgedMessages() on each child, then clearIncomingMessages() on the parent. Each child gives back permits only for the messages in its own queue (increaseAvailablePermits(cnx, currentSize)). The messages already in the parent's queue are released, and their permits are never given back. Exclusive and Failover subscriptions also use this path for ack-timeout and negative-ack redelivery: redeliverUnacknowledgedMessages(Set) falls back to it for subscription types other than Shared and Key_Shared.
  • MultiTopicsConsumerImpl.removeExpiredMessagesFromQueue(), used by the Shared/Key_Shared redeliverUnacknowledgedMessages(Set), discards matching messages from the parent queue the same way. The child's removeExpiredMessagesFromQueue() only counts and gives back permits for messages in the child's own queue.

Without a listener, this doesn't happen: the child gives the permit back in messageProcessed() when the message moves to the parent.

Impact

Each redelivery can lose up to one permit for every message that was waiting in the parent queue, which can be up to the receiver queue size. Messages wait in the parent queue whenever the listener runs slower than messages arrive. The lost permits stay lost until the child reconnects, because a reconnect resets availablePermits and sends a full flow. With repeated redeliveries, such as ack timeouts or negative acks on a slow listener, the broker-side permits for a child can drop to zero. That topic or partition then stops delivering until a reconnect.

beforeSeek() also clears the parent queue, but a seek disconnects and resubscribes the child consumers, which resets their permits, so the seek path isn't affected.

Error messages

None. The consumer stops receiving messages from the affected topic or partition.

Reproducing the issue

  1. Subscribe a multi-topic or partitioned consumer with a MessageListener that processes messages slowly (for example, it sleeps), so that messages build up in the parent incomingMessages queue. Use a small receiverQueueSize and an Exclusive or Failover subscription, with an ack timeout or negative acks that never get acknowledged.
  2. Publish more messages than the receiver queue size.
  3. Let several redeliveries run while the parent queue has messages in it.
  4. Watch the child consumers' availablePermits, or the broker-side consumer availablePermits in topic stats. They go down with each redelivery and don't recover, and delivery can stop until a reconnect.

Additional information

This came up in a review of #21767 (review comment). That PR changes how incoming queues are cleared, but it doesn't change this permit handling.

A possible fix: when the parent discards a TopicMessageImpl from its queue while listener != null, give its permit back to receivedByconsumer with increaseAvailablePermits(MessageImpl), which already ignores messages from an old connection. Do this in both clearIncomingMessages() on the redelivery path and removeExpiredMessagesFromQueue().

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/bug
    on Oct 20, 2026
  2. self-assigned this
    on Oct 20, 2026
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