binhuiliu commented on issue #12246:
URL: https://github.com/apache/gravitino/issues/12246#issuecomment-5164279367

   I completed an accelerated local reproduction against a clean Apache 
Gravitino v1.3.0 checkout using the embedded Hive Metastore.
   
   - Created, used, and closed 5 independent `HiveClientFactory` instances.
   - After repeated GC and allocation pressure, all 5 corresponding 
`HiveClientClassLoader` instances remained alive.
   - `Log4jLoggerFactory.registry` contained multiple classloader-specific 
`LoggerContext` entries.
   - As a diagnostic control only, removing the registry references and 
repeating the same GC procedure reduced the surviving classloaders from 5/5 to 
0/5.
   
   This confirms that, in this reproducer, the Log4j SLF4J adapter registry is 
sufficient to retain the closed classloaders. No thread interruption or 
ThreadLocal cleanup was required for the classloaders to become collectible 
after those registry references were removed.
   
   I also tested targeted cleanup through the public Log4j lifecycle API:
   
   ```java
   @Override
   public void close() throws IOException {
     try {
       LogManager.shutdown(LogManager.getContext(this, false));
     } finally {
       super.close();
     }
   }
   ```
   
   Placing this in `HiveClientClassLoader.close()` covers both normal factory 
shutdown and temporary classloaders closed during Hive-version detection or 
fallback.
   
   The Log4j `AbstractLoggerAdapter` is registered as a `LoggerContext` 
shutdown listener. Shutting down the specific context therefore removes only 
that context from `Log4jLoggerFactory.registry`; it does not clear the JVM-wide 
logging state.
   
   A two-factory isolation test also passed:
   
   - Closing factory A removed the logger context for A and allowed its 
classloader to be collected.
   - The context for factory B remained registered.
   - Factory B continued querying the Hive Metastore successfully.
   
   The focused diagnostic test, `TestCachedClientPool`, `TestHiveClientPool`, 
compilation, and Spotless checks passed.
   
   This candidate requires `compileOnly(libs.log4j.api)` in 
`hive-metastore-common`. Docker-based Hive 2/Hive 3, repeated-close, 
concurrency, and Kerberos/impersonation validation have not yet been run.


-- 
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