justinmclean opened a new issue, #10327:
URL: https://github.com/apache/gravitino/issues/10327

   ### What would you like to be improved?
   
   GravitinoServer.main registers a shutdown hook that only sleeps, while 
actual cleanup (GravitinoAuthorizerProvider.close(), gravitinoEnv.shutdown(), 
lineageService.close()) happens in server.stop() after server.join(). In 
production, bin/gravitino.sh stop sends SIGTERM, which triggers JVM shutdown 
hooks; this can bypass the post-join() cleanup path, causing app-level 
resources to not be closed during normal stop.
   
   ### How should we improve?
   
   Move graceful shutdown logic into the shutdown hook by invoking 
server.stop() there (or refactor into an idempotent gracefulStop() used by both 
hook and main flow). Keep server.stop() safe for multiple invocations, preserve 
the existing shutdown timeout behavior, and ensure cleanup runs on external 
termination signals as well as normal exits.
   
   Here's a unit test to help:
   ```
     @Test
     public void testMainShutdownHookShouldInvokeServerStop() throws 
IOException {
       Path sourceFile = 
Path.of("src/main/java/org/apache/gravitino/server/GravitinoServer.java");
       String source = Files.readString(sourceFile);
   
       int hookStart = source.indexOf("addShutdownHook");
       int joinIndex = source.indexOf("server.join();", hookStart);
       String hookBlock = source.substring(hookStart, joinIndex);
   
       assertTrue(
           hookBlock.contains("server.stop()"),
           "Shutdown hook should invoke server.stop() so app-level cleanup runs 
on SIGTERM");
     }
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to