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
7
u/laxika Dec 03 '22
This one isn't fixed yet, but at the moment they are targeting a fix for JDK 21.
For JDK 21? Ouch. :/
6
u/quantdata Dec 04 '22
Seeing as how the bug report was created on November 25 and Rampdown Phase One for JDK 20 is in 5 days, it makes sense they'd have to push it out. Good thing a new JDK releases every six months :)
4
u/cowwoc Dec 04 '22
They should be able to backport this fix seeing as it doesn't involve any sort of API changes. The first step is getting this bug fixed. Hopefully it doesn't sit idle too long.
2
u/neopointer Dec 03 '22
I haven't clicked through the link, but one thing that's important to understand is if these bugs happen regardless if you're using virtual threads or not.
5
u/cowwoc Dec 03 '22
These bugs are actually specific to platform threads, but since virtual threads sit on top of platform threads all thread types are impacted.
Virtual threads should theoretically have a lower impact because they spawn less platform threads over time.
55
22
3
u/CommanderStatue Dec 04 '22
You are doing fantastic work.
I echo grisly256's sentiment that a video or writeup of your process would provide a great wealth of knowledge to the community. Like you said in a later comment, bits and pieces of invaluable information are often hidden away in archaic places, like that Github gist which I have now downloaded lest it disappear tomorrow.
That being said, I understand that we're selfishly asking for a significant time commitment in this request. As such, if you are interested and would like any help at all in getting things set up (youtube channel, descriptions, recording setup, etc), feel free to DM me and I'll take on as much of the work as possible to help share the burden.
1
17
u/grisly256 Dec 03 '22
Do you have a YouTube channel that shows how you do this research?