[Bug][Java client] Possible race condition in consumer's clearIncomingMessages which causes a leak in memory limit controller and direct memory with pooled messages
- 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
master
### Minimal reproduce step
This is an issue that came up during a review. Please see #18938 for context.
### What did you expect to see?
When clearIncomingMessages is called, it should properly handle a case where more messages might be arriving while the messages are cleared.
### What did you see instead?
The current implementation of clearIncomingMessages will leak memory in the memory limit controller and also direct memory if more messages are arriving while the messages are cleared.
### Anything else?
_No response_
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Contributor guide
Research direction
Start by reading the consumer's clearIncomingMessages implementation and the context in issue #18938. Reproduce or inspect the concurrent-arrival case described in the issue, then verify that messages arriving during clearing release both memory-limit-controller accounting and pooled direct memory without leaks.
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
- Needs clarification
- Newbie friendliness
- 30/100