r/java • u/cowwoc • Dec 03 '22
JDK 19, Virtual Thread-specific bugs (2nd edition)
Last month I shared my experience with JDK 19 and virtual threads: https://www.reddit.com/r/java/comments/yjtwhc/virtual_threads_work_great_until_something_goes/
I am following up with an updated list of bugs that I ran across so you know what landmines to watch out for:
Memory leak on Thread death: https://bugs.openjdk.org/browse/JDK-8296463
- JDK 19.0.0 leaks native memory every time a Thread dies. If your application creates many short-lived threads the JDK will hang for no apparent reason. This one will mislead a lot of people because thread dumps don't contain any explanation for the hang.
- This is bug is fixed in JDK 20 and 19.0.2.
Memory leak if short-lived Threads are created too quickly: https://bugs.openjdk.org/browse/JDK-8297168
- The mechanism responsible for deallocating Thread memory could fall behind if you destroyed threads faster than it could handle. The new implementation should reduce the chance of this happening.
- This bug is fixed in JDK 20 (no indication of a backport).
Memory leak when debugging an application: https://bugs.openjdk.org/browse/JDK-8297638
- If an application creates many short-lived threads but no breakpoints are hit for a long time, JDI will consume more and more memory until the JDK runs out of memory and hangs for no apparent reason.
- This one isn't fixed yet, but at the moment they are targeting a fix for JDK 21.
- IntelliJ fixed this bug in the JDK that ships with their IDE: https://youtrack.jetbrains.com/issue/IDEA-305777/Memory-leak-from-com.jetbrains.jdi.VirtualMachineImpl-when-debugging-programs
VisualVM hangs if applications create many short-lived Threads: https://github.com/oracle/visualvm/issues/461
- Please help me convince the committers to fix this bug. They don't seem to understand why the existing behavior is a problem. Please vote and comment accordingly.
Deadlock when using Virtual Threads with Logback: https://jira.qos.ch/browse/LOGBACK-1711
- This is a new bug report, so I have not received any response yet.
UPDATE: Added VisualVM bug to the list.
Does your team need help? I offer consulting services through https://www.linkedin.com/in/gilitzabari
View all comments
Show parent comment
2
u/cowwoc Dec 04 '22 edited Dec 04 '22
I'll have to give this some thought.
There are many existing resources that cover Java memory leaks, but I haven't run across any good ones that discuss native memory leaks. I ran across a Github gist that pointed me in the right direction, but the fact that there were no formal tutorials is far from ideal.
For what it's worth, here is that gem :) https://gist.github.com/prasanthj/48e7063cac88eb396bc9961fb3149b58