Skip to content

Commit 44476a0

Browse files
authored
[test] Use Runtime.halt() in forked AvroCompat cluster process (#2692)
Avoid expensive shutdown hook cleanup in forked VeniceClusterInitializer JVM. Replace ProcessWrapper hook with Runtime.halt(0), cutting ~6 min per run. Keep existing shutdown behavior for main Gradle JVM to preserve FD safety.
1 parent 0d7b946 commit 44476a0

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

internal/venice-avro-compatibility-test/src/test/java/com/linkedin/venice/VeniceClusterInitializer.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ public static void main(String[] args) {
252252
int routerPort = Integer.parseInt(args[1]);
253253
VeniceClusterInitializer clusterInitializer = new VeniceClusterInitializer(storeName, routerPort);
254254

255-
Runtime.getRuntime().addShutdownHook(new Thread(clusterInitializer::close));
255+
/*
256+
* This forked JVM is ephemeral — the parent test destroys it via Process.destroy().
257+
* On SIGTERM, use Runtime.getRuntime().halt(0) to exit immediately instead of running the full
258+
* ProcessWrapper shutdown hooks (which add ~6 min of unnecessary teardown). The OS
259+
* reclaims FDs and ports on process death. Temp directories under java.io.tmpdir are
260+
* cleaned up by the OS or CI runner lifecycle — GHA runners are ephemeral VMs, and
261+
* local dev machines clean /tmp periodically. The ProcessWrapper shutdown hooks are
262+
* still valuable for the main Gradle test JVM where FD leaks accumulate across
263+
* sequential test classes — just not for this short-lived forked process.
264+
*/
265+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
266+
LOGGER.info("Forked cluster process for {} received shutdown signal, halting immediately", storeName);
267+
// Reference clusterInitializer to prevent GC from collecting it (and the cluster) prematurely.
268+
// The VeniceClusterInitializer keeps the embedded cluster alive until this hook runs.
269+
assert clusterInitializer != null;
270+
// Flush log buffers before halting so diagnostic messages are not lost
271+
LogManager.shutdown();
272+
Runtime.getRuntime().halt(0);
273+
}));
256274
}
257275
}

0 commit comments

Comments
 (0)