-
Bug
-
Resolution: Unresolved
-
P3
-
24, 25
Thread locals have unbounded lifetime and don't play well with thread pools. A ForkJoinPool can optionally be created with worker threads that clear thread locals between tasks, thus avoiding a build up of thread locals left behind by tasks executed in the pool. The common pool is setup to do this. Clearing all thread locals can lead to memory leaks for thread locals that are keeping native memory alive and don't have a Cleaner or other means to free the memory.
In the JDK, it means that TerminatingThreadLocal usages in the context of a thread in the common pool can leak native memory. More specifically, if a the thread in the common pool executes code that does I/O operations with a ByteBuffer backed by a byte[] in the heap, or scatter/gather I/O operations, or file systems, then the native memory cached by the TL caches is not released.
This issue has existed for some time but may not have been noticed, maybe because it should be rare to do I/O operations in the common pool, or maybe because the direct buffers in the TL buffer cache had a Cleaner. That Cleaner was removed inJDK 24 as part ofJDK-8344882 so the issue is a bit more noticeable now.
In the JDK, it means that TerminatingThreadLocal usages in the context of a thread in the common pool can leak native memory. More specifically, if a the thread in the common pool executes code that does I/O operations with a ByteBuffer backed by a byte[] in the heap, or scatter/gather I/O operations, or file systems, then the native memory cached by the TL caches is not released.
This issue has existed for some time but may not have been noticed, maybe because it should be rare to do I/O operations in the common pool, or maybe because the direct buffers in the TL buffer cache had a Cleaner. That Cleaner was removed inJDK 24 as part of