apache / apache/pulsar

[Bug][Java client] Possible race condition in closing consumer which causes a leak in memory limit controller and direct memory with pooled messages

Open
#18,938 1 comment 0 reactions 0 assignees View on GitHub
Stale type/bug
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 was an issue that came up in PR review comment https://github.com/apache/pulsar/pull/18928#discussion_r1049324152

### What did you expect to see?

There shouldn't be a race between org.apache.pulsar.client.impl.ConsumerImpl#closeAsync and org.apache.pulsar.client.impl.ConsumerImpl#messageReceived .

### What did you see instead?

It's possible that closeAsync and messageReceived are in a race and incoming messages don't get properly cleaned up. This can cause a leak in the memory limit controller and also leak direct memory.

### Anything else?

_No response_

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start by reading org.apache.pulsar.client.impl.ConsumerImpl#closeAsync and #messageReceived, then review the referenced PR discussion for the race scenario. The fix is complete when concurrent closing and message receipt no longer leave incoming pooled messages uncleaned or leak memory in the memory limit controller and direct memory.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.