Skip to content

ADP-2209: Let a KafkaEventStore close the admin client it opens - #20

Merged
puneet-traceable merged 1 commit into
mainfrom
ADP-2209-close-event-store
Dec 3, 2026
Merged

puneet-traceable merged 1 commit into
mainfrom
ADP-2209-close-event-store

Conversation

@puneet-traceable

Copy link
Copy Markdown
Collaborator

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.

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.
@puneet-traceable
puneet-traceable requested a review from a team as a code owner December 3, 2026 12:25
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Test Results

3 tests   3 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 06d3ae4.

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 8.48%. Comparing base (7c77c54) to head (06d3ae4).

Files with missing lines Patch % Lines
...ava/org/hypertrace/core/eventstore/EventStore.java 0.00% 1 Missing ⚠️
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     
Flag Coverage Δ
unit 8.48% <80.00%> (+8.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@puneet-traceable
puneet-traceable merged commit f977b48 into main Dec 3, 2026
13 of 15 checks passed
@puneet-traceable
puneet-traceable deleted the ADP-2209-close-event-store branch December 3, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants