You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "MaoWei Tian (Jira)" <ji...@apache.org> on 2024/12/21 08:06:00 UTC

[jira] [Updated] (KAFKA-18337) KafkaProducer Memory Leak in JMX Reporter

     [ https://issues.apache.org/jira/browse/KAFKA-18337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MaoWei Tian updated KAFKA-18337:
--------------------------------
    Description: 
Hello!

  If I use a Callback in the KafkaProducer.send()  to call the KafkaProducer.close(), the metrics will not be completely cleaned up.
{code:java}
//代码占位符
producer.send((new ProducerRecord<>("topic", "message test")),
        new Callback() {
            @Override
            public void onCompletion(RecordMetadata metadata, Exception exception) {
                producer.close();
            }
        }); {code}
Using this code to close the KafkaProducer can cause the AppInfoParser.unregisterAppInfo(JMX_PREFIX, clientId, metrics); within KafkaProducer.close() to execute before the client.close() in Sender.run().

This leads to {{client.close()}} eventually calling {{{}JmxReporter.reregister(){}}}, which prevents the metrics from being completely cleaned up

!image-2024-12-21-15-52-39-930.png!

 

 

The RecordAccumulator is utilized by metrics in JMX and cannot be garbage collected, ultimately leading to a memory leak。

  was:
Hello!

  If I use a Callback in the KafkaProducer.send()  to call the KafkaProducer.close(), the metrics will not be completely cleaned up.
{code:java}
//代码占位符
producer.send((new ProducerRecord<>("topic", "message test")),
        new Callback() {
            @Override
            public void onCompletion(RecordMetadata metadata, Exception exception) {
                producer.close();
            }
        }); {code}
Using this code to close the KafkaProducer can cause the AppInfoParser.unregisterAppInfo(JMX_PREFIX, clientId, metrics); within KafkaProducer.close() to execute before the client.close() in Sender.run().

This leads to {{client.close()}} eventually calling {{{}JmxReporter.reregister(){}}}, which prevents the metrics from being completely cleaned up

!image-2024-12-21-15-52-39-930.png!

The RecordAccumulator is utilized by JMX and cannot be garbage collected, ultimately leading to a memory leak。


> KafkaProducer Memory Leak in JMX Reporter
> -----------------------------------------
>
>                 Key: KAFKA-18337
>                 URL: https://issues.apache.org/jira/browse/KAFKA-18337
>             Project: Kafka
>          Issue Type: Bug
>          Components: clients
>            Reporter: MaoWei Tian
>            Priority: Major
>         Attachments: image-2024-12-21-15-52-39-930.png
>
>
> Hello!
>   If I use a Callback in the KafkaProducer.send()  to call the KafkaProducer.close(), the metrics will not be completely cleaned up.
> {code:java}
> //代码占位符
> producer.send((new ProducerRecord<>("topic", "message test")),
>         new Callback() {
>             @Override
>             public void onCompletion(RecordMetadata metadata, Exception exception) {
>                 producer.close();
>             }
>         }); {code}
> Using this code to close the KafkaProducer can cause the AppInfoParser.unregisterAppInfo(JMX_PREFIX, clientId, metrics); within KafkaProducer.close() to execute before the client.close() in Sender.run().
> This leads to {{client.close()}} eventually calling {{{}JmxReporter.reregister(){}}}, which prevents the metrics from being completely cleaned up
> !image-2024-12-21-15-52-39-930.png!
>  
>  
> The RecordAccumulator is utilized by metrics in JMX and cannot be garbage collected, ultimately leading to a memory leak。



--
This message was sent by Atlassian Jira
(v8.20.10#820010)