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][broker] Shared subscription stalls forever on a chunked message by 0asys · Pull Request #26396 · apache/pulsar

Conversation

@0asys

@0asys 0asys commented Aug 20, 2026 •
edited by merlimat
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Fixes #26395

Motivation

A Shared subscription stops dispatching for good when it reaches a chunk of a chunked message whose chunk 0 is already gone. This happens, for example, when the client's incomplete-chunk expiry or queue-full eviction acked the chunks it had, when a seek, TTL expiry or skip landed in the middle of the message, or after a reconnect, unload or restart lost the in-memory mapping.

SharedConsumerAssignor pins all chunks of a message to one consumer through uuidToConsumer, and only chunk 0 writes that mapping. A later chunk with no mapping hit:

if (metadata.getChunkId() != 0) {
    // Not the first chunk, skip it
    return null;
}

null sends the entry to addEntryToReplay. Replay reads always run before normal reads, so the dispatcher replays that same entry forever, the mark-delete position never moves, and nothing is logged. The only way out today is pulsar-admin topics skip.

A mapping that points at a removed consumer causes the same stall. removeConsumer never cleaned the mapping, so the remaining chunks stayed pinned to a consumer that no longer exists.

Modifications

SharedConsumerAssignor:

  • A chunk with chunkId != 0 and no mapping (an orphan) is now dispatched to the default consumer and logged at WARN. The client then discards it under its incomplete-chunk policy. The broker never acks it, so with client auto-ack disabled it stays in the backlog, but the subscription keeps moving.
  • Exception: when the entries come from a normal read and the replay queue holds an earlier position, the orphan goes back to replay instead. A normal read that was in flight when the owning consumer was removed can return chunk 1 after that consumer's chunk 0 was moved to replay. Replay reads come first and run in position order, so chunk 0 recreates the mapping and both chunks reach the same consumer. A real orphan is dispatched on its replay read, so it can't stall.
  • New removeConsumer(Consumer) and clear() methods drop stale mappings.

PersistentDispatcherMultipleConsumers:

  • Calls assignor.removeConsumer() in removeConsumer() and assignor.clear() in clearComponentsAfterRemovedAllConsumers().
  • On a normal read, passes the first position in the replay queue to assign().

Key_Shared doesn't use SharedConsumerAssignor, so its behavior is unchanged.

Verifying this change

New tests in SharedConsumerAssignorTest:

  • testOrphanChunkIsDispatchedInsteadOfReplayedForever: an orphan last chunk and an orphan middle chunk are dispatched, not replayed, and create no mapping. This fails on the old code.
  • testUuidMappingIsRemovedWhenConsumerIsRemoved: a removed consumer's mapping is dropped, and the remaining chunk goes to another consumer.
  • testChunkAfterPendingReplayIsReplayedInOrder: an unmapped chunk read behind a pending replay goes back to replay and later reaches the same consumer as its chunk 0. An orphan before the first replay position is still dispatched.
  • testClearRemovesAllUuidMappings: clear() empties the map.

SharedConsumerAssignorTest (7), PersistentDispatcherMultipleConsumersTest (17) and MessageChunkingSharedTest (4) pass locally, and checkstyle is clean.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

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

All reactions
@0asys
[fix][broker] stalled subscription on chunked message
4c1f01e
@Asthenia0412 Asthenia0412 mentioned this pull request Oct 16, 2026
[fix][broker] Prevent shared subscription stall on orphan chunked message #26942
Closed
5 of 14 tasks
Asthenia0412 pushed a commit to Asthenia0412/pulsar that referenced this pull request Oct 17, 2026
Asthenia0412 Trae Bot
[fix][broker] Prevent shared subscription stall on orphan chunked mes…
8d3d445
…sage

Issue: apache#26395

Motivation:
A Shared subscription stops dispatching forever when it runs into a chunk of a
chunked message whose chunk 0 is no longer in the uuidToConsumer cache. This
happens after topic unload, broker restart, or consumer disconnect.

SharedConsumerAssignor pins all chunks of a message to one consumer through the
in-memory uuidToConsumer map, which is only written when chunk 0 is assigned.
The original code returned null for any non-zero chunk with no cached mapping:

  if (metadata.getChunkId() != 0) {
      // Not the first chunk, skip it
      return null;
  }

The null return causes the entry to be handed to the replay queue. The
dispatcher drains the replay queue before every normal read, so it keeps
replaying the same orphan chunk forever and the mark-delete position never
moves. The same stall occurs when a consumer is removed while chunks are still
pinned to it — the mapping survives, the disconnected consumer has no permits,
so every remaining chunk also gets replayed forever.

Modifications:
- SharedConsumerAssignor.getConsumerForUuid(): orphan chunks (chunkId != 0 with
  no cached mapping) are now dispatched to the default consumer instead of
  returning null. The chunk 0 is what seeds the mapping, and the cursor always
  re-reads chunk 0 ahead of later chunks while it is still unacked, so a
  missing mapping means chunk 0 is already acked and the message can never be
  reassembled. Dispatching it lets the client discard the incomplete chunked
  message and move on. This path is logged at WARN so operators can detect
  silently-acked chunks.
- SharedConsumerAssignor.removeConsumer(Consumer): new public method that drops
  all uuid mappings pointing to a removed consumer. Called from the dispatcher
  when a consumer disconnects.
- SharedConsumerAssignor.clear(): new public method to drop all uuid mappings.
  Called when all consumers are removed from the dispatcher to prevent leaks
  from messages whose last chunk is never published.
- PersistentDispatcherMultipleConsumers: call assignor.removeConsumer() in
  removeConsumer() and assignor.clear() in clearComponentsAfterRemovedAllConsumers().
  PersistentStickyKeyDispatcherMultipleConsumers inherits both via super(), so
  the fix covers Key_Shared subscriptions too.

Note on PR apache#26396: this supersedes PR apache#26396, which has a merge conflict because
it modifies PersistentDispatcherMultipleConsumersClassic.java — a file that was
removed by PIP-379 (apache#26687) on 2026-09-22. The core fix in apache#26396 is correct;
this PR applies the same logic to the file set that exists on master today.

Testing:
- SharedConsumerAssignorTest.testOrphanChunkIsDispatchedInsteadOfReplayedForever:
  verifies orphan chunks are dispatched, not replayed, and do not create a
  uuid mapping. Fails on original code.
- SharedConsumerAssignorTest.testUuidMappingIsRemovedWhenConsumerIsRemoved:
  verifies the uuid mapping is cleaned up when its consumer is removed, and the
  remaining chunk can be dispatched to another consumer.
- SharedConsumerAssignorTest.testClearRemovesAllUuidMappings: verifies the map
  is cleared properly to prevent leaks.
- All existing SharedConsumerAssignorTest tests pass.
- All existing PersistentDispatcherMultipleConsumersTest tests pass.
@merlimat merlimat mentioned this pull request Oct 17, 2026
[fix][broker]Fixed an issue where the entire subscription would be blocked when a chunk message with an ID of zero did not exist. #25120
Closed
1 of 4 tasks
Asthenia0412 pushed a commit to Asthenia0412/pulsar that referenced this pull request Oct 18, 2026
Asthenia0412 @Asthenia0412
[fix][broker] Prevent shared subscription stall on orphan chunked mes…
44753ba
…sage

Issue: apache#26395

Motivation:
A Shared subscription stops dispatching forever when it runs into a chunk of a
chunked message whose chunk 0 is no longer in the uuidToConsumer cache. This
happens after topic unload, broker restart, or consumer disconnect.

SharedConsumerAssignor pins all chunks of a message to one consumer through the
in-memory uuidToConsumer map, which is only written when chunk 0 is assigned.
The original code returned null for any non-zero chunk with no cached mapping:

  if (metadata.getChunkId() != 0) {
      // Not the first chunk, skip it
      return null;
  }

The null return causes the entry to be handed to the replay queue. The
dispatcher drains the replay queue before every normal read, so it keeps
replaying the same orphan chunk forever and the mark-delete position never
moves. The same stall occurs when a consumer is removed while chunks are still
pinned to it — the mapping survives, the disconnected consumer has no permits,
so every remaining chunk also gets replayed forever.

Modifications:
- SharedConsumerAssignor.getConsumerForUuid(): orphan chunks (chunkId != 0 with
  no cached mapping) are now dispatched to the default consumer instead of
  returning null. The chunk 0 is what seeds the mapping, and the cursor always
  re-reads chunk 0 ahead of later chunks while it is still unacked, so a
  missing mapping means chunk 0 is already acked and the message can never be
  reassembled. Dispatching it lets the client discard the incomplete chunked
  message and move on. This path is logged at WARN so operators can detect
  silently-acked chunks.
- SharedConsumerAssignor.removeConsumer(Consumer): new public method that drops
  all uuid mappings pointing to a removed consumer. Called from the dispatcher
  when a consumer disconnects.
- SharedConsumerAssignor.clear(): new public method to drop all uuid mappings.
  Called when all consumers are removed from the dispatcher to prevent leaks
  from messages whose last chunk is never published.
- PersistentDispatcherMultipleConsumers: call assignor.removeConsumer() in
  removeConsumer() and assignor.clear() in clearComponentsAfterRemovedAllConsumers().
  PersistentStickyKeyDispatcherMultipleConsumers inherits both via super(), so
  the fix covers Key_Shared subscriptions too.

Note on PR apache#26396: this supersedes PR apache#26396, which has a merge conflict because
it modifies PersistentDispatcherMultipleConsumersClassic.java — a file that was
removed by PIP-379 (apache#26687) on 2026-09-22. The core fix in apache#26396 is correct;
this PR applies the same logic to the file set that exists on master today.

Testing:
- SharedConsumerAssignorTest.testOrphanChunkIsDispatchedInsteadOfReplayedForever:
  verifies orphan chunks are dispatched, not replayed, and do not create a
  uuid mapping. Fails on original code.
- SharedConsumerAssignorTest.testUuidMappingIsRemovedWhenConsumerIsRemoved:
  verifies the uuid mapping is cleaned up when its consumer is removed, and the
  remaining chunk can be dispatched to another consumer.
- SharedConsumerAssignorTest.testClearRemovesAllUuidMappings: verifies the map
  is cleared properly to prevent leaks.
- All existing SharedConsumerAssignorTest tests pass.
- All existing PersistentDispatcherMultipleConsumersTest tests pass.
merlimat added 2 commits October 21, 2026 15:45
@merlimat
Merge remote-tracking branch 'apache/master' into fix-26395-chunked-m…
e1bf8e9
…essage
@merlimat
[fix][broker] Replay an unmapped chunk behind a pending replay instea…
4fd594e
…d of dispatching it

A normal read in flight when a consumer is removed can return a later chunk
after that consumer's chunk 0 was moved to the replay queue. With the uuid
mapping dropped, the chunk was dispatched as an orphan ahead of its chunk 0.
On a normal read, send an unmapped non-first chunk after the first replay
position back to replay, so chunk 0 recreates the mapping first.

Assisted-by: Claude Code (claude-opus-5-5)
@merlimat

merlimat commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thanks @0asys, this is the right fix, and sorry it sat for so long. I pushed two commits to your branch to get it in:

  1. A merge of master. PersistentDispatcherMultipleConsumersClassic was removed by [improve][broker] PIP-379: Remove the classic Shared and Key_Shared dispatcher implementations #26687, so that hunk is gone.
  2. A guard for one race. After removeConsumer drops A's mappings, a normal read already in flight can still return chunk 1 after A's chunk 0 was moved to the replay queue. Before the guard, chunk 1 went to B as an orphan ahead of its chunk 0. The client would then discard it, and if the message was older than expireTimeOfIncompleteChunkedMessage it would also ack it. Now, on a normal read, an unmapped chunk after the first replay position goes back to replay, and both chunks reach the same consumer in order. A real orphan is still dispatched on its replay read. The new test is testChunkAfterPendingReplayIsReplayedInOrder.

I also updated the description; the Key_Shared note is gone, since that dispatcher doesn't use the assignor. #26942 and #25120 are closed in favor of this one.

All reactions

Sorry, something went wrong.

Uh oh!

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

merlimat
merlimat approved these changes Oct 21, 2026
View reviewed changes
@merlimat merlimat added this to the 5.1.0 milestone Oct 21, 2026
@merlimat
merlimat merged commit 91aac70 into apache:master Oct 22, 2026
44 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Oct 22, 2026
@0asys @merlimat @lhotari
[fix][broker] Shared subscription stalls forever on a chunked message (…
2d370b7
…#26396)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 91aac70)
@lhotari lhotari added release/5.0.1 cherry-picked/branch-5.0 labels Oct 22, 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
@0asys @merlimat @lhotari
[fix][broker] Shared subscription stalls forever on a chunked message (…
50029e5
…apache#26396)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 91aac70)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@0asys @merlimat @lhotari
[fix][broker] Shared subscription stalls forever on a chunked message (…
62aa221
…apache#26396)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 91aac70)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merlimat merlimat merlimat 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.1

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

[Bug] Shared subscription stalls forever on a chunked message whose first chunk is already acked

Uh oh!

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

3 participants

@0asys @merlimat @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.