developer-rpai commented on code in PR #18378:
URL: https://github.com/apache/iceberg/pull/18378#discussion_r4200674952
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -37,6 +38,17 @@ public class AuthSessionCache implements AutoCloseable {
private static final Logger LOG =
LoggerFactory.getLogger(AuthSessionCache.class);
+ /**
+ * A single daemon thread, shared by all cache instances for eviction tasks.
A shared executor
+ * avoids registering one JVM shutdown hook per cache instance: each hook
thread is constructed
+ * on the creating thread and would otherwise copy that thread's inheritable
thread-locals,
+ * pinning state such as closed Spark sessions for the life of the JVM. The
worker thread is
+ * created with inheritable thread-local variables disabled so it cannot pin
the creating
+ * thread's state either. The executor is deliberately exposed only as a
plain {@link Executor}
+ * (never an {@link ExecutorService}) so that {@link #close()} does not shut
it down.
+ */
+ private static final Executor SHARED_EVICTION_EXECUTOR =
newSharedEvictionExecutor();
Review Comment:
Good question. I checked whether the existing helper could work here, but it
cannot express what this executor needs, for two reasons:
1. `newExitingWorkerPool` wraps the pool with
`MoreExecutors.getExitingExecutorService`, which registers a JVM shutdown hook.
That hook is exactly what this PR removes: the hook thread is constructed on
the creating thread and copies its inheritable thread-locals, pinning state
such as Spark sessions for the life of the JVM (the problem reported in #18377).
2. Its thread factory (Guava `ThreadFactoryBuilder`) creates threads that
inherit thread-locals. This worker is deliberately created with
`inheritThreadLocals=false` so it cannot pin the creating thread's state either.
So reusing the helper would reintroduce both issues this PR fixes. The
custom factory is only there for the `inheritThreadLocals=false` semantic,
which `ThreadPools` cannot express today. Happy to add a `ThreadPools` overload
accepting a custom `ThreadFactory` if you would prefer the reuse, but the plain
helper is not a drop-in here.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]