Skip to content

Commit 2645dd6

Browse files
dkropachevclaude
andcommitted
fix: unregister event bus listener on init() failure
If super.init() or the initial route query fails, unregister the ClientRoutesUpdateEvent listener to prevent a leak when closeAsync() is not called by the caller on failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8ba3b51 commit 2645dd6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/ClientRoutesTopologyMonitor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,16 @@ public CompletionStage<Void> init() {
165165
// buildNodeEndPoint (called during the subsequent refreshNodes) can use ClientRoutesEndPoint.
166166
// If the server does not support CLIENT_ROUTES_CHANGE, the control connection will fail with
167167
// a ConnectionInitException and the error propagates naturally.
168-
return super.init().thenCompose(ignored -> queryClientRoutesAndCache(null, null));
168+
return super.init()
169+
.thenCompose(ignored -> queryClientRoutesAndCache(null, null))
170+
.whenComplete(
171+
(result, error) -> {
172+
if (error != null) {
173+
context
174+
.getEventBus()
175+
.unregister(clientRoutesUpdateKey, ClientRoutesUpdateEvent.class);
176+
}
177+
});
169178
}
170179

171180
/** Returns the {@link ClientRoutesConfig} this handler was built from. */

0 commit comments

Comments
 (0)