[Bug] consumer.pause is not working as expected
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Version
3.1.1
### Minimal reproduce step
#6965
``` java
Consumer consumer = pulsarClient.newConsumer(Schema.STRING)
.topic("myTopic")
.consumerName(consumerName)
.subscriptionType(SubscriptionType.Shared)
.subscriptionName("mySub")
.messageListener(listener)
.subscribe();
log.info("[consumer pause],topic={}", crawlerInnerParseTopic);
consumer.pause();
return consumer;```
### What did you expect to see?
consumer stop receive msg
### What did you see instead?
consumer still receive msg.
### Anything else?
I tracked the code and found that when the consumer is set to pause, it doesn't report AvailablePermits to the broker. If AvailablePermits reported to the broker before pausing are not fully utilized, the broker will continue to send messages until AvailablePermits are exhausted. Therefore, when pausing is set, AvailablePermits should be reported to the broker once as 0.
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Contributor guide
Research direction
Start with the Java consumer.pause() reproducer in this issue and linked example #6965, then trace how AvailablePermits are reported when a consumer pauses. Reproduce the behavior with a Shared subscription and message listener; done means a paused consumer receives no further messages and the behavior has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100