Closed boris-petrov closed 3 months ago
From the stacktrace you are using virtual threads. JavaMail/JakartaMail uses synchronized blocks in the code which will pin the carrier thread. My understanding is if enough carrier threads get pinned the worker pool will get exhausted and there will be no workers to run the async tasks. I would make sure that IdleManager.watch is not called from a virtual thread and re-test this.
There was an old abandon branch that Bill was working on but never merged: https://github.com/jakartaee/mail-api/issues/404 Might be something to try. My understanding is you will always have to handle errors from the server to retry or abort.
@jmehrens thank you for the response. I think you are right that in this case this is what happens. I should have seen it but I was searching for pinned threads in the thread dump but for some reason the dump from jcmd
didn't show correctly blocked threads on synchronized
. So I got confused. Thank you for helping me find it! :) I'll close the issue.
IdleManager is a bit special in that it might be worth switching to ReentrantLock. Looks trivial to do and class is marked experimental so compatibility change is not a big deal. Out of all of the classes here this one might good candidate to make virtual thread friendly.
Well, users of the class don't/shouldn't care whether it uses synchronized
or locks underneath so it wouldn't even be a compatibility-change. But I'm not sure whether IdleManager
itself doesn't depend on IMAPFolder
using synchronized
and so it has to use it too...
I was just looking at code idlemanager code. You are right I need to look at the whole stack trace as there are other locks later on.
I was thinking this might have been a candidate to fix but if it starts to get outside of idlemanager then this will face the same issues as https://github.com/eclipse-ee4j/angus-mail/issues/128 and I'll have to leave this this closed.
In the end the whole thing might not be needed. The Loom guys already have a prototype for a fix of the synchronized
thread-pinning issue so you could just wait and the issue will go away by itself. :) Hopefully for JDK 24. Java Mail is definitely not the only project with such a "problem" so no need to worry about it. It's up to us, the users, to figure it out for now - we're the ones using a cutting-edge feature after all. :)
P.S. Missed a "not" above. :)
Describe the bug
IdleManager.watch
freezes foreverTo Reproduce I don't have a reproduction, I just see it happening in production now and then. Here's the stack trace:
This freezes forever. I'm not sure why and what I can do about it.
Expected behavior
watch
to not freeze.Screenshots N/A
Desktop (please complete the following information): N/A
Smartphone (please complete the following information): N/A
Mail server:
courier-imap
5.0.13Additional context The library used is
com.sun.mail:jakarta.mail:1.6.7
.I don't understand why that would block. I see exactly 30 minutes after that in the
courier-imap
logs:imapd[1158]: TIMEOUT
- which is, I believe, the default IDLE timeout of the server.Is that an issue in the mail server or in Java Mail? What can I do about that? I've set
mail.imap.connectiontimeout
andmail.imap.writetimeout
to10_000
. I can't setmail.imap.timeout
as that seems to cause all kinds of deadlocks but that's another story.