You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "xelathan (via GitHub)" <gi...@apache.org> on 2025/02/16 09:23:09 UTC

[PR] KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil [kafka]

xelathan opened a new pull request, #18919:
URL: https://github.com/apache/kafka/pull/18919

   MemoryRecordsBuilder not closed in RecordsUtil.
   Closed implicitly with `try`
   
   https://issues.apache.org/jira/browse/KAFKA-18806
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil [kafka]

Posted by "xelathan (via GitHub)" <gi...@apache.org>.
xelathan commented on PR #18919:
URL: https://github.com/apache/kafka/pull/18919#issuecomment-2661578406

   Build finished with unrelated test failure in `ConsumerCoordinatorTest > testOutdatedCoordinatorAssignment `
   Issue is tracked with [KAFKA-15900](https://issues.apache.org/jira/browse/KAFKA-15900)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil [kafka]

Posted by "xelathan (via GitHub)" <gi...@apache.org>.
xelathan commented on code in PR #18919:
URL: https://github.com/apache/kafka/pull/18919#discussion_r1957411153


##########
clients/src/main/java/org/apache/kafka/common/record/RecordsUtil.java:
##########
@@ -89,10 +89,11 @@ protected static ConvertedRecords<MemoryRecords> downConvert(Iterable<? extends
                 buffer = Utils.ensureCapacity(buffer, buffer.position() + recordBatchAndRecords.batch.sizeInBytes());
                 recordBatchAndRecords.batch.writeTo(buffer);
             } else {
-                MemoryRecordsBuilder builder = convertRecordBatch(toMagic, buffer, recordBatchAndRecords);
-                buffer = builder.buffer();
-                temporaryMemoryBytes += builder.uncompressedBytesWritten();
-                numRecordsConverted += builder.numRecords();
+                try (MemoryRecordsBuilder builder = convertRecordBatch(toMagic, buffer, recordBatchAndRecords)) {

Review Comment:
   If `Records#downConvert` is being removed by [#18897](https://github.com/apache/kafka/pull/18897) then closing wouldn't really be necessary. I'll go ahead and close the PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #18919:
URL: https://github.com/apache/kafka/pull/18919#discussion_r1957408912


##########
clients/src/main/java/org/apache/kafka/common/record/RecordsUtil.java:
##########
@@ -89,10 +89,11 @@ protected static ConvertedRecords<MemoryRecords> downConvert(Iterable<? extends
                 buffer = Utils.ensureCapacity(buffer, buffer.position() + recordBatchAndRecords.batch.sizeInBytes());
                 recordBatchAndRecords.batch.writeTo(buffer);
             } else {
-                MemoryRecordsBuilder builder = convertRecordBatch(toMagic, buffer, recordBatchAndRecords);
-                buffer = builder.buffer();
-                temporaryMemoryBytes += builder.uncompressedBytesWritten();
-                numRecordsConverted += builder.numRecords();
+                try (MemoryRecordsBuilder builder = convertRecordBatch(toMagic, buffer, recordBatchAndRecords)) {

Review Comment:
   Do we really need this close? the builder returned by `convertRecordBatch` is already closed. see
   
   https://github.com/apache/kafka/blob/d0e516a87207b04f6266c59712775b5f01c1ed87/clients/src/main/java/org/apache/kafka/common/record/RecordsUtil.java#L124
   
   Additionally, `RecordsUtil` is useless in trunk and it will be removed by #18897



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #18919:
URL: https://github.com/apache/kafka/pull/18919#discussion_r1957411650


##########
clients/src/main/java/org/apache/kafka/common/record/RecordsUtil.java:
##########
@@ -89,10 +89,11 @@ protected static ConvertedRecords<MemoryRecords> downConvert(Iterable<? extends
                 buffer = Utils.ensureCapacity(buffer, buffer.position() + recordBatchAndRecords.batch.sizeInBytes());
                 recordBatchAndRecords.batch.writeTo(buffer);
             } else {
-                MemoryRecordsBuilder builder = convertRecordBatch(toMagic, buffer, recordBatchAndRecords);
-                buffer = builder.buffer();
-                temporaryMemoryBytes += builder.uncompressedBytesWritten();
-                numRecordsConverted += builder.numRecords();
+                try (MemoryRecordsBuilder builder = convertRecordBatch(toMagic, buffer, recordBatchAndRecords)) {

Review Comment:
   > I'll go ahead and close the PR.
   
   yes and thanks for your contribution. Please feel free to ping me if you have other PRs needs to be reviewed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil [kafka]

Posted by "xelathan (via GitHub)" <gi...@apache.org>.
xelathan closed pull request #18919: KAFKA-18806: Resource leak in MemoryRecordsBuilder in RecordsUtil
URL: https://github.com/apache/kafka/pull/18919


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org