GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][client] Resume a multi-topics consumer's paused partitions while a batch receive waits for messages by merlimat · Pull Request #27597 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Motivation

Problem: a multi-topics consumer (partitioned topic or several topics) whose batchReceive() policy has maxNumMessages above half of the receiver queue can wait for its timeout, or hang forever if the policy has no timeout. This happens even though the messages it needs are already in the client.

  • The builder raises receiverQueueSize to at least maxNumMessages, so the common case of a batch the size of the receiver queue is affected.
  • ConsumerBatchReceiveTest.testBatchReceivePartitionedTopic (maxNumMessages=50, no timeout, receiverQueueSize=50, 3 partitions) hit this in CI. The first attempt hung until the 300 s method timeout in 6 runs since 2026-11-08, including master.

Example: MultiTopicsConsumerImpl pauses a partition consumer when its shared queue reaches receiverQueueSize. Once any partition is paused, it also pauses the others when the queue is above half.

if (size >= maxReceiverQueueSize
        || (size > sharedQueueResumeThreshold && !pausedConsumers.isEmpty())) {
    pausedConsumers.add(consumer);

The paused partitions resume only when the queue drops to half:

if (incomingMessages.size() <= getCurrentReceiverQueueSize() / 2 && !pausedConsumers.isEmpty()) {

With a queue of 50, a batch of 50 and no timeout:

  1. The partitions hand over 80 of 100 messages before the application asks for a batch, and all of them get paused.
  2. The first batch takes 50, leaving 30.
  3. The second batch needs 50, but 30 is above the resume threshold of 25. Nothing takes from the queue until the batch completes, so the remaining 20 messages stay in the paused partitions and the batch never completes.

Modifications

  • While a batch receive is pending and the queue is not full, also resume the paused partitions. The queue stays bounded: a resumed partition is paused again once the queue is full, and a pending batch receive is completed as soon as the queue holds its batch.
if (size <= maxReceiverQueueSize / 2 || (size < maxReceiverQueueSize && hasPendingBatchReceive())) {
  • Add MultiTopicsConsumerImplTest.testBatchReceiveWaitingForMessagesResumesPausedConsumers. It drives two mocked partition consumers into this state: a queue of 4, a batch of 4, 7 messages handed over, and 3 left after the first batch. It fails without the fix and passes with it.

Verifying this change

  • The new unit test fails on master ("expected [2] but found [1]": the second batch never asked a paused partition for more messages) and passes with the fix. The rest of MultiTopicsConsumerImplTest passes.
  • ConsumerBatchReceiveTest (269), TopicsConsumerImplTest (21) and PatternTopicsConsumerImplTest (18) pass.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@merlimat
[fix][client] Resume a multi-topics consumer's paused partitions whil…
2928712
…e a batch receive waits for messages

A multi-topics consumer pauses a partition consumer when its shared queue is
full, and resumes the paused ones only once the queue drops to half of the
receiver queue size. A batch receive takes nothing until it has its batch, so
with maxNumMessages above half of the receiver queue (the builder raises the
queue to at least maxNumMessages) and the queue left between the two, the batch
receive waited for its timeout, or forever without one, while the paused
partitions held the messages it needed.

Also resume the paused consumers while a batch receive is pending and the queue
is not full. This fixes ConsumerBatchReceiveTest.testBatchReceivePartitionedTopic
hanging until its 300 s timeout.
codelipenghui
codelipenghui approved these changes Nov 12, 2026
View reviewed changes
@merlimat
merlimat merged commit 1ef4e5c into apache:master Nov 12, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@merlimat
merlimat deleted the mmerli/batch-receive-partitioned-hang branch November 12, 2026 20:55
lhotari pushed a commit that referenced this pull request Nov 17, 2026
@merlimat @lhotari
[fix][client] Resume a multi-topics consumer's paused partitions whil…
f563dd5
…e a batch receive waits for messages (#27597)

(cherry picked from commit 1ef4e5c)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 17, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][client] Resume a multi-topics consumer's paused partitions whil…
2ee599c
…e a batch receive waits for messages (apache#27597)

(cherry picked from commit 1ef4e5c)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][client] Resume a multi-topics consumer's paused partitions whil…
f89e5ac
…e a batch receive waits for messages (apache#27597)

(cherry picked from commit 1ef4e5c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@merlimat @codelipenghui @lhotari
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.