Skip to content
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

Fix ImapIdleChA for scheduling race condition #8670

Merged

Conversation

artembilan
Copy link
Member

The IMAP IDLE is long-lived process and can be blocked waiting for any reply from the server.
This way it is not suited to be used in a TaskScheduler especially when it has only one thread in its pool in Spring Boot by default. Another concurrent scheduled task is exactly an ImapMailReceiver.IdleCanceller. With a single thread in a TaskScheduler pool it cannot be reached therefore we never cancel and IDLE task and cannot react to the connection loss properly

  • Rework the ImapIdleChannelAdapter logic to use a regular Executor and while() loop with a Thread.sleep() when we lose connection
  • Clean up the ImapMailReceiverTests from TaskScheduler not used anymore.
  • Expose new taskExecutor option in the ImapIdleChannelAdapterSpec for Java DSL
  • Enable ImapMailReceiverTests.testIdleWithMessageMapping() with an attempt to see if this fix covers an unclear problem exposed before

The IMAP IDLE is long-lived process and can be blocked
waiting for any reply from the server.
This way it is not suited to be used in a `TaskScheduler`
especially when it has only one thread in its pool in Spring Boot by default.
Another concurrent scheduled task is exactly an `ImapMailReceiver.IdleCanceller`.
With a single thread in a `TaskScheduler` pool it cannot be reached
therefore we never cancel and IDLE task and cannot react to the connection loss properly

* Rework the `ImapIdleChannelAdapter` logic to use a regular `Executor` and `while()` loop
with a `Thread.sleep()` when we lose connection
* Clean up the `ImapMailReceiverTests` from `TaskScheduler` not used anymore.
* Expose new `taskExecutor` option in the `ImapIdleChannelAdapterSpec` for Java DSL
* Enable `ImapMailReceiverTests.testIdleWithMessageMapping()` with an attempt to see
if this fix covers an unclear problem exposed before
@artembilan
Copy link
Member Author

@garyrussell garyrussell merged commit e4c1851 into spring-projects:main Jul 12, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants