gharris1727 opened a new pull request, #14783: URL: https://github.com/apache/kafka/pull/14783
There are currently many tests which instantiate sockets and channels, but don't close them. The vast majority of these sockets and channels are created via Selector and SocketServer, and are associated with clients and servers which are not closed properly. Many of these leaks are silent, and have gone unnoticed for years. To allow us to detect these leaks and prevent future ones, we should have a Junit5 Extension which automatically checks for leaks in each test, and fails tests which leak clients. This can be opt-out, so that known or unavoidable leaks can be annotated, but most leaks can be proactively found and fixed before merging. Implementation note: I tried to keep the `main` changes as small as possible, making use of the javax.net Factory classes to create a layer of indirection in the NetworkContext. I've kept the locking to a minimum in order to not impact the normal operation of the broker and clients. I felt that adding the static NetworkContext was a much less invasive change than dependency-injecting the factories and possibly having to add more constructors to the Kafka clients. It also has the effect that the test changes are also minimal, as we don't have to rewrite any existing tests to get this leak checking functionality. I added an `Ignore` annotation that disables the extension on a per-class or per-method basis to give an opt-out mechanism, although I expect to merge this PR only after most or all of the discovered fixes have been merged. This PR will cause many test failures for tests that are not compliant, and should not be merged as-is. For the set of leaks I found with this testing methodology, see: * #14729 * #14750 * #14751 * #14754 * #14761 * #14762 * #14763 * #14764 * #14769 * #14771 * https://issues.apache.org/jira/browse/KAFKA-15834 ### 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
