-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MINOR: KafkaProducerTest - Fix resource leakage and replace explicit invocation of close() method with try with resources #18678
base: trunk
Are you sure you want to change the base?
Conversation
Heya, thank you for this contribution! A question from my side - how did you detect this resource leak? I vaguely remember that in other parts of Kafka we use a functionality of the testing framework to confirm that we don't have more threads hanging around than we are expecting which helped us catch cases similar to this one, but I am wondering why that wasn't caught in this case. |
Great question @clolov! In other test suites, we use For this specific test, @pramithas if we add the following lines, we are able to detect leaks in two tests:
Let's start with adding this leak detection here in the short term and then perhaps @pramithas , if you are interested, you may want to pick up https://issues.apache.org/jira/browse/KAFKA-16072 ? |
@clolov After reviewing the test cases, I noticed that we missed closing the resources in a few of them. So, it was a manual observation in this case. @divijvaidya Thanks for the great insights on how we're detecting leaks in Kafka already. I'll implement your suggestions shortly and then move on to KAFKA-16072. |
@divijvaidya Please review now. The kafka producer threads is given a specific prefix And, I have moved the assertion logic to Note: If there is any resource leakage in a test, all the following tests will fail as well. |
I'd like to weakly push back on adding new stateless assertions that threads aren't leaked. I would recommend merging just the leak fixes, and not the AfterEach assertion or TestUtils method. |
Thank you, @gharris1727,for your thoughtful feedback. You raised a valid concern about cascading test failures in this approach. However, if we ensure all existing tests are fixed, any new test introduced with a resource leak would be caught during local development before reaching CI. Given this safeguard, would cascading failures still be a significant issue? |
In few tests,
producer.close()
method was not called. Thus, wrapped the logic of producer creation insidetry with resources
.Also, wherever the resources were closed with explicit invocation of
close()
method, I replaced those withtry with resources
.All the tests are passing after the changes.
Committer Checklist (excluded from commit message)