Skip to content

Commit

Permalink
[fix][client] Fix memory leak when message size exceeds max message s…
Browse files Browse the repository at this point in the history
…ize and batching is enabled (#23967)
  • Loading branch information
lhotari authored and merlimat committed Feb 12, 2025
1 parent 9d767b3 commit 2620871
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public OpSendMsg createOpSendMsg() throws IOException {

// handle mgs size check as non-batched in `ProducerImpl.isMessageSizeExceeded`
if (op.getMessageHeaderAndPayloadSize() > getMaxMessageSize()) {
cmd.release();
producer.semaphoreRelease(1);
producer.client.getMemoryLimitController().releaseMemory(
messages.get(0).getUncompressedSize() + batchAllocatedSizeBytes);
Expand All @@ -286,6 +287,7 @@ public OpSendMsg createOpSendMsg() throws IOException {
ByteBuf encryptedPayload = producer.encryptMessage(messageMetadata, getCompressedBatchMetadataAndPayload());
updateAndReserveBatchAllocatedSize(encryptedPayload.capacity());
if (encryptedPayload.readableBytes() > getMaxMessageSize()) {
encryptedPayload.release();
producer.semaphoreRelease(messages.size());
messages.forEach(msg -> producer.client.getMemoryLimitController()
.releaseMemory(msg.getUncompressedSize()));
Expand Down

0 comments on commit 2620871

Please sign in to comment.