Repository navigation
ADP-2209: Let a KafkaEventStore close the admin client it opens - #20
Merged
Merged
Conversation
Issue: trace-enricher's integration tests restart the app in one JVM for each config. Every stopped instance left Kafka clients running, so threads and heap grew until the run ran out of memory. Why here: TE's session mapping opens a KafkaEventStore, whose init() creates an AdminClient. EventStore had no close(), so nothing could release that client or its thread. Fix: EventStore extends AutoCloseable with a default no-op close(), so other stores are unchanged. KafkaEventStore.close() closes the admin client; it is safe before init and when called twice.
Test Results3 tests 3 ✅ 0s ⏱️ Results for commit 06d3ae4. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
==========================================
+ Coverage 0.00% 8.48% +8.48%
- Complexity 0 7 +7
==========================================
Files 10 11 +1
Lines 219 224 +5
Branches 11 11
==========================================
+ Hits 0 19 +19
+ Misses 219 204 -15
- Partials 0 1 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kotharironak
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: trace-enricher's integration tests restart the app in one JVM for each config. Every stopped instance left Kafka clients running, so threads and heap grew until the run ran out of memory. Why here: TE's session mapping opens a KafkaEventStore, whose init() creates an AdminClient. EventStore had no close(), so nothing could release that client or its thread. Fix: EventStore extends AutoCloseable with a default no-op close(), so other stores are unchanged. KafkaEventStore.close() closes the admin client; it is safe before init and when called twice.
Description
KafkaEventStore.init() creates a Kafka AdminClient, but EventStore had no way to release it. Once a store was initialised, its admin client, with its network connections and its kafka-admin-client-thread, stayed alive until the JVM exited. A service that creates a store and later stops it, then starts a new one in the same JVM (as integration tests that restart an app do), leaked one admin client and its thread on every restart.
This PR:
makes EventStore extend AutoCloseable, with a default close() that does nothing, so other implementations do not need any change.
adds KafkaEventStore.close(), which closes the admin client opened by init(). It is safe to call before init() and more than once.
Producers and consumers created by the store are not closed by it. Callers still close each of them, as the javadoc on close() says.
Testing
Added KafkaEventStoreCloseTest. It counts the live kafka-admin-client-thread | KafkaEventStore-* threads and checks that:
init() starts an admin client and close() stops it;
close() before init() does nothing;
calling close() twice does nothing the second time.
No broker is needed, because the admin client starts without one.
./gradlew build passes locally.
Checklist:
My changes generate no new warnings
I have added tests that prove my fix is effective or that my feature works
Any dependent changes have been merged and published in downstream modules
Documentation
No docs change needed. The new close() is documented in its javadoc.
Warnings box: I left it unticked because I haven't checked the build for new warnings. Tick it only if you've confirmed there are none.
Dependent-changes box: I ticked it because this PR doesn't depend on anything unreleased. The default close() keeps it compatible.
One compatibility case: an existing EventStore implementation that already has a close() throwing a checked exception would stop compiling. Each EventStore implementation in this repo builds, but code outside it could still be affected.