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] Close dispatchers stuck due to mismatch between dispatcher.consumerList and dispatcher.consumerSet by poorbarcode · Pull Request #22270 · apache/pulsar

Conversation

@poorbarcode

@poorbarcode poorbarcode commented Mar 14, 2024

Copy link
Copy Markdown
Contributor

Motivation

2024-03-13T07:47:36,071+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentTopic - [persistent://{tenat}/{ns}/{topic name}] Global topic inactive for 86400 seconds, closed repl producers
2024-03-13T07:47:36,073+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.Consumer - Disconnecting consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=5, consumerName=082c9, address=/127.0.0.6:34293}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.Consumer - Disconnecting consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=10, consumerName=f0c65, address=/127.0.0.6:32911}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - Removed consumer Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=5, consumerName=7f82f, address=/127.0.0.6:39763} with pending 0 acks
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - [persistent://{tenat}/{ns}/{topic name} / {subscription}] Trying to remove a non-connected consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=10, consumerName=f0c65, address=/127.0.0.6:32911}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.Consumer - Disconnecting consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=5, consumerName=7f82f, address=/127.0.0.6:39763}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - Removed consumer Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=18, consumerName=1aebe, address=/127.0.0.6:33045} with pending 0 acks
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.Consumer - Disconnecting consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=18, consumerName=b44be, address=/127.0.0.6:44907}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - [persistent://{tenat}/{ns}/{topic name} / {subscription}] Trying to remove a non-connected consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=5, consumerName=082c9, address=/127.0.0.6:34293}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.Consumer - Disconnecting consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=10, consumerName=a2fc6, address=/127.0.0.6:54177}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - [persistent://{tenat}/{ns}/{topic name} / {subscription}] Trying to remove a non-connected consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=18, consumerName=b44be, address=/127.0.0.6:44907}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.Consumer - Disconnecting consumer: Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=18, consumerName=1aebe, address=/127.0.0.6:33045}
2024-03-13T07:47:36,074+0000 [pulsar-inactivity-monitor-25-1] INFO  org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers - Removed consumer Consumer{subscription=PersistentSubscription{topic=persistent://{tenat}/{ns}/{topic name}, name={subscription}}, consumerId=10, consumerName=a2fc6, address=/127.0.0.6:54177} with pending 0 acks
2024-03-13T07:47:36,186+0000 [pulsar-io-4-22] WARN  org.apache.pulsar.broker.service.persistent.PersistentTopic - [persistent://{tenat}/{ns}/{topic name}] Attempting to subscribe to a fenced topic

The logs were printed on our cluster(2.11.2)

  • The consumer {clientCnx 127.0.0.6:44907, consumerId: 18} has been removed twice when calling dispatcher.disconnectAllConsumers.[1]
  • Pulsar printed Trying to remove a non-connected consumer when removing the consumer {clientCnx 127.0.0.6:44907, consumerId: 18} at the second time, which means this consumer is duplicated in dispatcher.consumerList.[2]
  • Once the log "Trying to remove a non-connected consumer" is printed, the closeFuture of dispatcher will never be completed, leading to the process of topic.delete being stuck.
  • The topic stays in a fenced state.

[1]: dispatcher.disconnectAllConsumers

public synchronized CompletableFuture<Void> disconnectAllConsumers() {
  consumerList.forEach(consumer -> consumer.disconnect(isResetCursor, assignedBrokerLookupData));
}

[2]: dispatcher.removeConsumer

public synchronized void removeConsumer(Consumer consumer) throws BrokerServiceException {
    // decrement unack-message count for removed consumer
    addUnAckedMessages(-consumer.getUnackedMessages());
    if (consumerSet.removeAll(consumer) == 1) {
        consumerList.remove(consumer);
        log.info("Removed consumer {} with pending {} acks", consumer, consumer.getPendingAcks().size());
        if (consumerList.isEmpty()) {
            if (closeFuture != null) {
                closeFuture.complete(null); // Once the log "Trying to remove a non-connected consumer" was printed, it means the closeFuture will never be completed.
            }
        } 
    } else {
        log.info("[{}] Trying to remove a non-connected consumer: {}", name, consumer);
    }
}

Modifications

I haven't found the logic of repeating consumer in dispatcher.consumerList yet(it may caused by a consumer that has been added twice, and dispatcher.consumerSet merged two adding), I just fixed the follow-up issue.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: x

Sorry, something went wrong.

Uh oh!

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

All reactions
@poorbarcode
[fix] [broker] Delete topic stuck due to mismatch between dispatcher.…
550c42c
…consumerList and dispatcher.consumerSet
@poorbarcode poorbarcode added type/bug The PR fixed a bug or issue reported a bug release/3.0.4 release/3.2.2 release/2.11.5 labels Mar 14, 2024
@poorbarcode poorbarcode added this to the 3.3.0 milestone Mar 14, 2024
@poorbarcode poorbarcode self-assigned this Mar 14, 2024
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Mar 14, 2024
@poorbarcode poorbarcode changed the title [fix] [broker] Delete topic stuck due to mismatch between dispatcher.consumerList and dispatcher.consumerSet [fix] [broker] Close dispatchers stuck due to mismatch between dispatcher.consumerList and dispatcher.consumerSet Mar 15, 2024
@poorbarcode poorbarcode mentioned this pull request Mar 16, 2024
[fix] [broker] fix mismatch between dispatcher.consumerList and dispatcher.consumerSet #22283
Merged
1 of 4 tasks
poorbarcode added 2 commits March 16, 2024 10:05
@poorbarcode
add a test
c59501b
@poorbarcode
add a test
2f67d1b
hanmz
hanmz approved these changes Mar 18, 2024
View reviewed changes

@hanmz hanmz left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
lhotari
lhotari reviewed Mar 18, 2024
View reviewed changes
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java Resolved

Uh oh!

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

@poorbarcode
poorbarcode requested a review from lhotari March 18, 2024 15:47
lhotari
lhotari approved these changes Mar 18, 2024
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
@poorbarcode
add another test
b709898
@poorbarcode poorbarcode mentioned this pull request Mar 19, 2024
[fix][broker] Fix one potential to add duplicated consumer #20583
Closed
2 of 5 tasks
@codecov-commenter

codecov-commenter commented Mar 19, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.68%. Comparing base (bbc6224) to head (4882977).
⚠️ Report is 1247 commits behind head on master.

Files with missing lines Patch % Lines
...sistent/PersistentDispatcherMultipleConsumers.java 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #22270      +/-   ##
============================================
+ Coverage     73.57%   73.68%   +0.10%     
- Complexity    32624    32802     +178     
============================================
  Files          1877     1887      +10     
  Lines        139502   139488      -14     
  Branches      15299    15293       -6     
============================================
+ Hits         102638   102778     +140     
+ Misses        28908    28750     -158     
- Partials       7956     7960       +4     
Flag Coverage Δ
inttests 26.58% <46.15%> (+2.00%) ⬆️
systests 24.54% <46.15%> (+0.22%) ⬆️
unittests 72.95% <92.30%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...sistent/PersistentDispatcherMultipleConsumers.java 74.52% <92.30%> (+0.20%) ⬆️

... and 103 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

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

codelipenghui
codelipenghui requested changes Mar 21, 2024
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It looks like we don't need this PR if we follow this comment to fix the issue. I have tested on my laptop.

Sorry, something went wrong.

Uh oh!

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

All reactions
@poorbarcode
address comment
4882977
@poorbarcode

poorbarcode commented Mar 21, 2024

Copy link
Copy Markdown
Contributor Author

It looks like we don't need this PR if we follow this #22283 (review) to fix the issue. I have tested on my laptop.

Changed the implementation: Just add a defensive code to avoid the topic not being unloaded anymore: remove the consumers which are not mismatched between consumerSet and consumerList, and print an error log

All reactions

Sorry, something went wrong.

Uh oh!

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

@poorbarcode
poorbarcode requested a review from codelipenghui March 21, 2024 14:14
codelipenghui
codelipenghui approved these changes Mar 22, 2024
View reviewed changes
@poorbarcode poorbarcode added the ready-to-test label Mar 22, 2024
@poorbarcode

poorbarcode commented Mar 22, 2024

Copy link
Copy Markdown
Contributor Author

/pulsarbot rerun-failure-checks

All reactions

Sorry, something went wrong.

Uh oh!

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

@poorbarcode
poorbarcode merged commit cba1600 into apache:master Mar 23, 2024
poorbarcode added a commit that referenced this pull request Mar 26, 2024
@poorbarcode
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
c8ee206
…cher.consumerList and dispatcher.consumerSet (#22270)

(cherry picked from commit cba1600)
@poorbarcode poorbarcode added the cherry-picked/branch-2.11 label Mar 26, 2024
poorbarcode added a commit that referenced this pull request Mar 26, 2024
@poorbarcode
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
94edfe4
…cher.consumerList and dispatcher.consumerSet (#22270)

(cherry picked from commit cba1600)
@poorbarcode poorbarcode added the cherry-picked/branch-3.0 label Mar 26, 2024
poorbarcode added a commit that referenced this pull request Mar 26, 2024
@poorbarcode
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
ab88cee
…cher.consumerList and dispatcher.consumerSet (#22270)

(cherry picked from commit cba1600)
@poorbarcode poorbarcode added the release/3.2.3 label Mar 26, 2024
poorbarcode added a commit that referenced this pull request Mar 26, 2024
@poorbarcode
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
310102f
…cher.consumerList and dispatcher.consumerSet (#22270)

(cherry picked from commit cba1600)
@poorbarcode poorbarcode added cherry-picked/branch-3.2 cherry-picked/branch-2.10 release/2.10.7 and removed release/3.2.2 labels Mar 26, 2024
@lhotari lhotari added release/3.2.2 and removed release/3.2.3 labels Mar 27, 2024
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 15, 2024
@poorbarcode @mukesh-ctds
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
d1b4de1
…cher.consumerList and dispatcher.consumerSet (apache#22270)

(cherry picked from commit cba1600)
(cherry picked from commit 94edfe4)
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 17, 2024
@poorbarcode @mukesh-ctds
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
da48c3e
…cher.consumerList and dispatcher.consumerSet (apache#22270)

(cherry picked from commit cba1600)
(cherry picked from commit 94edfe4)
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 17, 2024
@poorbarcode @mukesh-ctds
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
0368473
…cher.consumerList and dispatcher.consumerSet (apache#22270)

(cherry picked from commit cba1600)
(cherry picked from commit 94edfe4)
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 19, 2024
@poorbarcode @mukesh-ctds
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
bd46f9a
…cher.consumerList and dispatcher.consumerSet (apache#22270)

(cherry picked from commit cba1600)
(cherry picked from commit 94edfe4)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 23, 2024
@poorbarcode @srinath-ctds
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
4764b44
…cher.consumerList and dispatcher.consumerSet (apache#22270)

(cherry picked from commit cba1600)
(cherry picked from commit 94edfe4)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request May 13, 2024
@poorbarcode @nodece
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
2595ff2
…cher.consumerList and dispatcher.consumerSet (apache#22270)

(cherry picked from commit cba1600)
hanmz pushed a commit to hanmz/pulsar that referenced this pull request Feb 12, 2025
@poorbarcode hanmz
[fix] [broker] Close dispatchers stuck due to mismatch between dispat…
dd4b2d7
…cher.consumerList and dispatcher.consumerSet (apache#22270)
@TakaHiR07 TakaHiR07 mentioned this pull request Dec 17, 2025
[fix][broker] fix delayedMessagesCount error in InMemoryDelayedDeliveryTracker #25076
Closed
2 of 5 tasks
@FlorentinDUBOIS FlorentinDUBOIS mentioned this pull request Aug 23, 2026
[Bug] Shared dispatcher leaks negative aggregate availablePermits on consumer removal: deferred flow credit is discarded while the full consumer counter is debited #26416
Closed
3 tasks done
FlorentinDUBOIS added a commit to FlorentinDUBOIS/pulsar that referenced this pull request Aug 23, 2026
@FlorentinDUBOIS
[fix][broker] Debit un-acked messages only when the consumer is actua…
b3cd75c
…lly removed

### Motivation

`PersistentDispatcherMultipleConsumers#removeConsumer` debited the subscription's
un-acknowledged message count by the departing consumer's own count before it
established whether that consumer was still registered:

    addUnAckedMessages(-consumer.getUnackedMessages());
    if (consumerSet.removeAll(consumer) == 1) {

The `else` branch below is the defensive path added by apache#22270 for a consumer that is
still in `consumerList` but no longer in `consumerSet`, so that the topic can still be
unloaded. Reaching it means the consumer was already removed once, and the first
removal already debited its un-acknowledged messages. The unguarded debit therefore
subtracts them a second time and drives `totalUnackedMessages` negative.

That counter is what `maxUnackedMessagesOnSubscription` throttles on, and nothing
resets it while the dispatcher lives — `clearComponentsAfterRemovedAllConsumers()`
resets the available-permits aggregate but deliberately leaves it alone. A negative
value therefore silently disables the throttle for the lifetime of the dispatcher.

### Modifications

Move the debit inside the `consumerSet.removeAll(consumer) == 1` guard, so that only
the removal which actually unregisters the consumer accounts for it. The defensive
branch needs no debit of its own, for the same reason: the first removal already made
it.

### Verifying this change

Adds `SharedSubscriptionAvailablePermitsInvariantTest#testRemovingSameConsumerTwiceDebitsUnackedMessagesOnce`,
which leaves a consumer holding ten un-acknowledged deliveries, removes it twice and
requires the subscription counter to end at zero. Without this change it ends at -10.

This is broker-internal accounting: no public API, configuration or wire-protocol
change.

Signed-off-by: Florentin Dubois <[email protected]>
This was referenced Aug 23, 2026
[fix][broker] Debit only credited permits when removing a Shared consumer #26417
Closed
[fix][broker] Debit un-acked messages only when the consumer is actually removed #26422
Merged
@merlimat merlimat mentioned this pull request Oct 23, 2026
[fix][broker] The offline consumer is not removed from the consumerList #14970
Closed
1 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes
@hanmz hanmz hanmz approved these changes

Uh oh!

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

Assignees

@poorbarcode poorbarcode

Labels

cherry-picked/branch-2.10 cherry-picked/branch-2.11 cherry-picked/branch-3.0 cherry-picked/branch-3.2 doc-not-needed Your PR changes do not impact docs ready-to-test release/2.10.7 release/2.11.5 release/3.0.4 release/3.2.2 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Milestone

3.3.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

5 participants

@poorbarcode @codecov-commenter @lhotari @codelipenghui @hanmz
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.