Skip to content

[fix][broker] Prevent stale consumer removal from removing replacements - #26652

Merged
merlimat merged 3 commits into
apache:masterfrom
Denovo1998:fix-consumer-removal-accounting
Oct 14, 2026
Merged

merlimat merged 3 commits into
apache:masterfrom
Denovo1998:fix-consumer-removal-accounting

Conversation

@Denovo1998

@Denovo1998 Denovo1998 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #26422.
Related to #26289.

Motivation

A delayed removal of an old consumer can match a replacement consumer through Consumer.equals(), even though they are different instances. This can remove the replacement from dispatcher membership and debit the old consumer's unacknowledged messages again. For Key_Shared subscriptions, the stale removal can also remove the replacement from the selector and prevent further delivery.

Modifications

  • Require the exact registered consumer instance before removing dispatcher membership or debiting its unacknowledged messages.
  • Remove consumer list entries by identity while maintaining priority counts, including defensive cleanup and failed-add cleanup.
  • Protect replacement consumers from stale AUTO_SPLIT removals.
  • Preserve cleanup for STICKY additions that complete after dispatcher removal. Remove selector ranges and classic recently-joined records by identity.
  • Apply the changes to both classic and newer persistent dispatchers.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

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

@merlimat
merlimat requested a review from lhotari September 19, 2026 15:48

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for protecting replacement consumers across both dispatcher implementations. The identity checks look sound for completed additions, but the new Key_Shared early return drops cleanup for a STICKY addition that completes after removal. Please preserve that cleanup and cover the delayed-add case.

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The one open point is handled in cc0311f. STICKY consumers now run the full removal path even when they are no longer registered, so a late selector addition is cleaned up on the repeated close. The selector and the Classic recently-joined map remove by identity, so an equal replacement keeps its range. The new test covers the late addition and the repeated close.

The branch now conflicts with master, so it needs a merge of master before it can go in.

@Denovo1998

Copy link
Copy Markdown
Contributor Author

LGTM. The one open point is handled in cc0311f. STICKY consumers now run the full removal path even when they are no longer registered, so a late selector addition is cleaned up on the repeated close. The selector and the Classic recently-joined map remove by identity, so an equal replacement keeps its range. The new test covers the late addition and the repeated close.

The branch now conflicts with master, so it needs a merge of master before it can go in.

Okay, conflict processed.

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for merging master. The merge dropped the Classic dispatcher edits because master removed those classes, and nothing in the tree refers to them any more. The remaining fix is unchanged: the STICKY removal path in PersistentStickyKeyDispatcherMultipleConsumers.java:345-356 and the identity-based selector removal still cover the late addition and the repeated close, and the new tests are intact.

@merlimat
merlimat merged commit 668c16d into apache:master Oct 14, 2026
43 checks passed
lhotari pushed a commit that referenced this pull request Oct 15, 2026
lhotari pushed a commit that referenced this pull request Oct 16, 2026
scmi-c8y pushed a commit to scmi-c8y/pulsar that referenced this pull request Oct 30, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants