Skip to content
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

Fix Kafka Client leaks in the SampleFilterIntegrationTest. #519

Merged
merged 2 commits into from
Aug 7, 2023

Conversation

k-wall
Copy link
Contributor

@k-wall k-wall commented Aug 4, 2023

Type of change

  • Bugfix

Description

Fix Kafka Client leaks in the SampleFilterIntegrationTest. Closing the test doesn't close the admin/consumer/producers
that it created.

Additional Context

Why are you making this pull request?

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Write tests
  • Make sure all tests pass
  • Review performance test results. Ensure that any degradations to performance numbers are understood and justified.
  • Make sure all Sonar-Lint warnings are addressed or are justifiably ignored.
  • Update documentation
  • Reference relevant issue(s) and close them after merging
  • For user facing changes, update CHANGELOG.md (remember to include changes affecting the API of the test artefacts too).

@k-wall k-wall requested a review from gracegrimwood August 4, 2023 13:12
@k-wall k-wall force-pushed the fix-sample-client-leaks branch from 60f4cac to 65bb1e7 Compare August 4, 2023 13:12
@k-wall k-wall added the tests label Aug 4, 2023
Copy link
Member

@SamBarker SamBarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -212,6 +211,9 @@ void assertConsumerRecordEquals(String value) {
*/
void close() {
this.tester.close();
this.admin.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im happy with this as a tactical choice, but longer term? Would a better fix not be to have test.close() ensure all the clients it has handed out are closed?

I also wondered about making FilterIntegrationTest.admin etc some sort of lazy function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed (incorrectly) that tester.close() also closed everything that had been created by the tester (i.e. admin, producer, consumer). Having the tester check what it created and then ensure they're all correctly disposed of on close makes the most sense to me.

Copy link
Contributor Author

@k-wall k-wall Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes we want the lifespan of the Kafka object (producer, consumer, admin) to extend beyond the lifespan of Kroxylicious instance. We use this so that we can ensure that clients are capable of reconnecting through a replacement instance.

One way to solve this problem might be to break the association between the lifecycle of the tester the lifecycle of the kroxylicious. That would retain the flexibility we need to write this sort of test:

try(var tester = kroxyliciousTester();// No longer creates a kroxylicious instance
     var admin = tester.admin()) { 
     try(var kroxy = tester.kroxylicious()) { // Creates a Kroxylicious
        // ...
        //  do something with admin
     } 
     try(var kroxy = tester.kroxylicious()) { // Creates a Kroxylicious
        // ...
        // check admin reconnects
     }
}

It would also mean tester.close() could be given the semantics to ensure that everything it created has been closed, which is more obvious for the programmer to reason about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds like a good way to go. I've raised that proposal as #526

Copy link
Contributor

@robobario robobario Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that conflict with your other issue #378, if we can make clients independent of the existence of a Kroxylicious instance?

Another way would be to make KroxyliciousTester able to clean up dangling clients on close, and in special cases like the resilience test we construct them in the test using config supplied by the tester so they are detached from Tester.

moved discussion to issue #526

Copy link
Contributor

@gracegrimwood gracegrimwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! LGTM

@@ -212,6 +211,9 @@ void assertConsumerRecordEquals(String value) {
*/
void close() {
this.tester.close();
this.admin.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed (incorrectly) that tester.close() also closed everything that had been created by the tester (i.e. admin, producer, consumer). Having the tester check what it created and then ensure they're all correctly disposed of on close makes the most sense to me.

@k-wall k-wall force-pushed the fix-sample-client-leaks branch from c08f149 to 53183c0 Compare August 7, 2023 09:22
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@k-wall k-wall merged commit 4ebc00e into kroxylicious:main Aug 7, 2023
@k-wall k-wall deleted the fix-sample-client-leaks branch August 7, 2023 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants