[ https://issues.apache.org/jira/browse/KAFKA-18337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
MaoWei Tian reassigned KAFKA-18337: ----------------------------------- Assignee: MaoWei Tian > 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 > Assignee: 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)