pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[Bug][client] Pooled buffers leak when duplicate batch messages are filtered

Open void-ptr974 opened this issue 1 month ago • 3 comments

Search before reporting

  • [x] I searched existing issues and PRs and did not find a report of this specific duplicate-filtering buffer leak.

User environment

  • Client library: Java, master / 5.1.0-SNAPSHOT.
  • Verified commit: 7538399a8b06ab0fda28fa535aa70aed8e396211.
  • Local validation: macOS x86_64, Eclipse Temurin 25.0.2, Gradle wrapper.
  • Validation scope: local client tests using existing client/connection fixtures and the real acknowledgment grouping tracker. No running broker was used, and released versions have not been checked.

Issue Description

With poolMessages=true, the Java consumer fails to release buffer references when its local acknowledgment grouping tracker filters duplicate messages from a batch.

In ConsumerImpl.receiveIndividualMessagesFromBatch, each MessageImpl is created before the duplicate check. The duplicate branch only increments skippedMessages and continues:

if (acknowledgmentsGroupingTracker.isDuplicate(message.getMessageId())) {
    skippedMessages++;
    continue;
}

The message is never delivered to the application, so the application cannot call release(). The client must release references belonging to messages it discards.

Expected: after filtering both duplicate messages and releasing the caller's input-frame reference, the receive queue is empty and the frame's reference count is zero.

Actual: the queue is empty, but two references remain.

Scenario (two messages per batch) Final receive queue size Final input-frame refCnt
Duplicate batch, poolMessages=true 0 2
Duplicate batch, poolMessages=false 0 0
Normal batch, poolMessages=true, after application release 0 0

The retained buffers affect the consumer process. Repeated occurrences may accumulate retained buffers; OOM has not been reproduced.

Error messages

The local regression assertion fails only for the pooled duplicate case:

[frame references after caller release and queue drain, pool=true duplicate=true]
expected: 0
 but was: 2

3 tests completed, 1 failed

Both controls pass. Test retries were disabled.

Reproducing the issue

The local test exercises the normal messageReceived() entry point with a valid serialized batch:

  1. Create a consumer for a persistent topic with poolMessages=true, acknowledgment receipts disabled, and a long acknowledgment grouping interval to keep the test's ACK pending.
  2. Acknowledge an entry through the normal acknowledgment API so the real grouping tracker recognizes that entry as acknowledged. The duplicate result is not mocked.
  3. Serialize a valid two-message batch for the same ledger/entry ID using the existing Commands serializers.
  4. Deliver it through messageReceived() without a broker ACK set that would filter out those items before message creation.
  5. Wait for the internal executor, release the caller's frame reference, and check the queue and frame reference count: queue size is 0, but refCnt() is 2.
  6. Repeat with pooling disabled, and with a normal unacknowledged pooled batch whose messages are received and released. Both controls reach refCnt() == 0.

This verifies the client-side ownership failure at the receive boundary; it does not claim a broker integration reproduction.

Additional information

The ownership chain at the verified commit is:

This concerns local ACK-tracker duplicate filtering. Broker ackSet filtering in newSingleMessage() occurs before MessageImpl creation and does not exhibit this leak.

A fix also needs to account for dead-letter message ownership: the message can already have been added to possibleToDeadLetter before this duplicate check, so releasing it while leaving that same object cached would be unsafe.

Are you willing to submit a PR?

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

void-ptr974 avatar Oct 23 '26 15:10 void-ptr974

Anyone interested is welcome to claim this issue and work on a fix.

void-ptr974 avatar Oct 23 '26 15:10 void-ptr974

I am willing to pick this up @void-ptr974

ManasBhole avatar Oct 24 '26 16:10 ManasBhole

Hey, it looks like the issue is still open. Would you mind if i work on this @void-ptr974 ?

sandeepreddy54744 avatar Nov 14 '26 16:11 sandeepreddy54744