You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "skoppu22 (via GitHub)" <gi...@apache.org> on 2026/04/10 15:07:08 UTC
Re: [PR] CASSANALYTICS-143 Fix various leaks in CDC caching and bridge implementation [cassandra-analytics]
skoppu22 commented on code in PR #189:
URL: https://github.com/apache/cassandra-analytics/pull/189#discussion_r3065100548
##########
cassandra-analytics-cdc/src/main/java/org/apache/cassandra/bridge/CdcBridgeFactory.java:
##########
@@ -165,6 +168,51 @@ private static VersionSpecificBridge create(@NotNull String label)
}
}
+ /**
+ * Returns whether the shutdown hook has been registered.
+ */
+ @VisibleForTesting
+ static boolean isShutdownHookRegistered()
+ {
+ return SHUTDOWN_HOOK_REGISTERED.get();
+ }
+
+ /**
+ * Registers a JVM shutdown hook that calls {@link #close()} to release classloader resources.
+ * Clears the {@link TypeCache} first so type references are released before classloaders close.
+ * Uses CAS to ensure the hook is registered at most once.
+ */
+ @VisibleForTesting
+ static void maybeRegisterShutdownHook()
+ {
+ if (SHUTDOWN_HOOK_REGISTERED.compareAndSet(false, true))
+ {
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try
+ {
+ TypeCache.clear();
+ close();
+ }
+ catch (Exception e)
+ {
+ // best-effort cleanup during JVM shutdown
+ }
+ }, CdcBridgeFactory.class.getSimpleName() + "-shutdown"));
+ }
+ }
+
+ /**
+ * Closes all cached bridge classloaders and clears the cache. Call during application shutdown
+ * to release classloader resources and delete temp JAR files.
+ *
+ * Do not use this method outside testing; rely on the shutdown hook logic to clean things up in prod.
Review Comment:
Do we need to add this comment for CassandraBridgeFactory's close as well?
--
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: commits-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org