-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leaking fiber monitors when running in custom IORuntime using JDK 21 virtual threads #3929
Comments
It seems the leak is due to the nodes of the |
Hmm, that's actually really annoying. I think we'll want to rethink that thread-local strategy for virtual threads since there's a 1-to-1 fiber-to-virtual-thread mapping. Ideally we'd be using the carrier thread's local storage, not the virtual thread's for the bag. But that's probably not possible.
But we should probably still fix this anyway. |
(I'm not seriously suggesting we use that, just found it interesting.) |
Thanks, makes sense that we are not the only ones needing that 😇
even if we wanted to these new JVMs make it annoying/impossible to access their internals |
You know, I'm actually very surprised that thread locals aren't just cleaned up with the thread itself. Arman is right that we really want the carrier thread here, not the virtual thread, but even with the virtual thread this doesn't feel like a thing that should be leaking (just a thing that would be very inefficient). |
@djspiewak as Daniel U pointed out, the leak is actually our fault:
We are lacking a "packing" mechanism for |
Right but that's a weak reference, so it shouldn't prevent the cleanup of |
Right, but the |
The solution is probably to do something annoying with We wouldn't need JDK 21 for this (since it's not loom specific), so we could probably resolve it in 3.5.x |
I've proposed a fix for the general issue in #3964. But from a performance standpoint I still think that we need a different solution for virtual threads. The current mechanism adds a lot of overhead:
|
Fixed the leak in #3964 and opened a follow-up. |
Run with
-Dcats.effect.tracing.mode=FULL
on JDK21.Observe heapdump.hprof -> biggest objects -> cats.effect.unsafe.FiberMonitor -- many MBs
cc @djspiewak
The text was updated successfully, but these errors were encountered: