-
Notifications
You must be signed in to change notification settings - Fork 1.1k
IMAP idle channel adapter reconnect behavior seems to be different when (not) using a mail filter expression #9297
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
Comments
OK. So, your proposal is to iterate I'm failing at the moment to find a useful utility which does that for us... |
So, I came up with this utility method:
Is that OK for what you are looking for? |
Hi, Thanks for your quick responses. This method would indeed nicely iterate to find the |
Right. So, pushing that one then. |
Fixes: #9297 For a normal `jakarta.mail.StoreClosedException: * BYE Jakarta Mail Exception: java.net.SocketException: Connection reset` the `ImapIdleChannelAdapter.callIdle()` results in a resubmission (and reconnection) with logging 'Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.'` However, when `selectorExpression` is in used and that one is based on mail `Message` object, we may fail with `FolderClosedException` which is wrapped to the `SpelEvaluationException` and some other stack traces. So, `jakarta.mail.MessagingException` might be deep in the cause chain. * Fix `ImapIdleChannelAdapter` via introducing `getJakartaMailMessagingExceptionFromCause()` utility method which searches for the `jakarta.mail.MessagingException` in cause chain. * Rework `ImapIdleChannelAdapter.callIdle()` logic to rely on this new method (cherry picked from commit 272fcd0)
Fixes: #9297 For a normal `jakarta.mail.StoreClosedException: * BYE Jakarta Mail Exception: java.net.SocketException: Connection reset` the `ImapIdleChannelAdapter.callIdle()` results in a resubmission (and reconnection) with logging 'Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.'` However, when `selectorExpression` is in used and that one is based on mail `Message` object, we may fail with `FolderClosedException` which is wrapped to the `SpelEvaluationException` and some other stack traces. So, `jakarta.mail.MessagingException` might be deep in the cause chain. * Fix `ImapIdleChannelAdapter` via introducing `getJakartaMailMessagingExceptionFromCause()` utility method which searches for the `jakarta.mail.MessagingException` in cause chain. * Rework `ImapIdleChannelAdapter.callIdle()` logic to rely on this new method (cherry picked from commit 272fcd0)
Behavior observed in: Spring Integration 6.2.1 (as no recent changes I assume it applies to later versions as well)
Describe the bug
I have some Imap idle channel adapters set up with various settings. I notice that occasionally, one of the mailservers has a connection hiccup. For a normal
jakarta.mail.StoreClosedException: * BYE Jakarta Mail Exception: java.net.SocketException: Connection reset
this results in a resubmission (and reconnection) with logging 'Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.'.However, on the idle channel adapter that also has a 'mail-filter-expression' it seems that this may also result in a problem while the filter expression is being evaluated, causing a
SpelEvaluationException
with as root exception a 'jakarta.mail.FolderClosedException'. Since in this specific case the ImapIdleChannelAdapter#callIdle method will break the while loop in the else clause because theex.getCause()
is not an instanceofjakarta.mail.MessagingException
(even thoughex.getCause().getCause().getCause()
is).I know that I can register an ApplicationEventListener that acts upon the ApplicationEvent published by the
ImapIdleChannelAdapter#publishException
(and essentially restarts the adapter), but I feel that it is odd that there is nice built-in behavior to restart the adapter when some jakarta.mail.MessagingException occurs as the cause of the current exception, but not when it is a deeper nested cause, because built-in SpEL expression logic is used. In my eyes, this would be 'fixed' as well if ImapIdleChannelAdapter line 203 would do check whether the stack trace of the Exception has a MessagingException cause, instead of only checking the cause directly above. (i.e. a (fictional) 'hasCause' instead of 'getCause')?Expected behavior
The IMAP idle channel adapter has the same reconnect behavior whether a 'mail filter expression' is used or not
Sample
Although this is quite difficult to reproduce, as it is essentially seems to be caused by a server hiccup that is not generally the case for large mail providers such as Gmail or Outlook, I have provided a small XML configuration sample below of the used configuration.
Log message with (reversed) stack trace when the issue occurs:
The text was updated successfully, but these errors were encountered: