arxhr007 opened a new pull request, #24100: URL: https://github.com/apache/kafka/pull/24100
`Admin.close(Duration)` invokes `MetricsReporter.close()` twice on the same reporter instance — once on the caller thread (`KafkaAdminClient#close` calls `metrics.close()`) and once on the I/O thread (`AdminClientRunnable` calls `closeQuietly(metrics)` in its `finally` block). Reporters that cannot tolerate a second `close()` call (resources released on first close, counting reporters, non-idempotent cleanup) break or misbehave. Rather than coordinating which of the two teardown paths may close `Metrics`, this makes `Metrics.close()` itself idempotent via an `AtomicBoolean` guard — matching `AutoCloseable` semantics and protecting every caller, including other clients and custom reporters that cannot safely be closed twice. `KafkaAdminClientTest.testMetricsReporterClosedOnce` reproduces the bug with a counting `MetricsReporter` (asserts `close()` is invoked exactly once; fails with count=2 on trunk), and `MetricsTest.testCloseIsIdempotent` covers the idempotency contract directly. ### Tests `./gradlew :clients:test --tests MetricsTest --tests KafkaAdminClientTest` — all tests pass, including the two new ones. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
