Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,35 @@ public void testBatchMessageIndexAckForExclusiveSubscription() throws PulsarClie
// broker also need to handle the available permits.
Assert.assertEquals(received.size(), 100);
}

@Test
public void testDoNotRecycleAckSetMultipleTimes() throws Exception {
final String topic = "persistent://my-property/my-ns/testSafeAckSetRecycle";

Producer<byte[]> producer = pulsarClient.newProducer()
.batchingMaxMessages(10)
.blockIfQueueFull(true).topic(topic)
.create();

Consumer<byte[]> consumer = pulsarClient.newConsumer()
.acknowledgmentGroupTime(1, TimeUnit.MILLISECONDS)
.topic(topic)
.subscriptionName("test")
.subscribe();

final int messages = 100;
for (int i = 0; i < messages; i++) {
producer.sendAsync("Hello Pulsar".getBytes());
}

// Should not throw an exception.
for (int i = 0; i < messages; i++) {
consumer.acknowledgeCumulative(consumer.receive());
// make sure the group ack flushed.
Thread.sleep(2);
}

producer.close();
consumer.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private boolean doImmediateBatchIndexAck(BatchMessageIdImpl msgId, int batchInde
}

final ByteBuf cmd = Commands.newAck(consumer.consumerId, msgId.ledgerId, msgId.entryId, bitSet, ackType, null, properties);
bitSet.recycle();
cnx.ctx().writeAndFlush(cmd, cnx.ctx().voidPromise());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,6 @@ public static ByteBuf newAck(long consumerId, long ledgerId, long entryId, BitSe

ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.ACK).setAck(ack));
ack.recycle();
if (ackSet != null) {
ackSet.recycle();
}
ackBuilder.recycle();
messageIdDataBuilder.recycle();
messageIdData.recycle();
Expand Down