I am developing an Inbox listener for [email protected] using IMAP protocol with Spring Integration Mail. I am using XOAUTH2 to Autheticate and SSL.
The email is an outlook email, so as I want to use XOAUTH2 to be able to connect to the inbox, I have registered an application in Microsoft Entra, created a secret and given the corresponding Imap permissions to the application:
After that, via Powershell I have added [email protected] to be able to access to that emails inbox with a Jwt. The tutorial to configure the application I have followed is defined here.
Once I have granted the permissions to access to [email protected] I have defined the following IntegrationFlow.
I want to use an IdleAdapter in order to process the received messages as they enter in the inbox. As the token expires every hour, I have defined a javaMailAuthenticator to reauthenticate every hour (when AuthenticationException occurs).
I want to do the reconnection authomatically, so I have defined shouldReconnectAutomatically(true). As I want to process the messages and work with their body and attachments, I have defined .autoCloseFolder(false).
My integration flow is:
@Bean
public IntegrationFlow imapFlow(
@Value("${debug.mode: true}") String debug,
@Qualifier("outlookApiService") AccessTokenService accessTokenService,
@Qualifier("complexHandler") MessageHandler handler
) {
return IntegrationFlows
.from(Mail.imapIdleAdapter("imap://outlook.office365.com/INBOX")
.javaMailProperties(p -> {
p.put("mail.debug", debug); // Enable debugging. Shows idle protocol logs.
p.put("mail.debug.auth", "true"); // Enable debugging. Shows idle protocol logs.
p.put("mail.imap.auth.mechanisms", "XOAUTH2");
p.put("mail.imap.ssl.enable", "true");
p.put("mail.imap.closefoldersonstorefailure", "true");
//p.put("mail.imap.timeout", "5000"); <- I have already played with timeouts
})
.javaMailAuthenticator(
new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
var accesstoken = accessTokenService.getAccessToken(
"myTenantID",
new AccessTokenRequest(
"myClientId",
"https://outlook.office365.com/.default",
"mySecret",
"client_credentials"
)
).getAccessToken();
logger.info("Authentication launched with token {}", accesstoken);
return new PasswordAuthentication("[email protected]", accesstoken);
}
}
)
.shouldReconnectAutomatically(true)
//Avoid closing folder when message fetching. This allows message reading without raising error.
//The MessageHandler MUST close the folder.
.autoCloseFolder(false)
.shouldDeleteMessages(false) // Flag to delete messages of the email folder whe are listening to
.autoStartup(true))
.handle(handler)
.get();
}
The authentication is going Ok:
2024-05-23 13:45:22.659 INFO 75598 --- [ restartedMain] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2024-05-23 13:45:23.472 INFO 75598 --- [ restartedMain] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2024-05-23 13:45:23.472 INFO 75598 --- [ restartedMain] o.s.i.channel.PublishSubscribeChannel : Channel 'application.errorChannel' has 1 subscriber(s).
2024-05-23 13:45:23.472 INFO 75598 --- [ restartedMain] o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger
2024-05-23 13:45:23.472 INFO 75598 --- [ restartedMain] o.s.integration.channel.DirectChannel : Channel 'application.imap2Flow.channel#0' has 1 subscriber(s).
2024-05-23 13:45:23.472 INFO 75598 --- [ restartedMain] o.s.i.endpoint.EventDrivenConsumer : started imap2Flow.org.springframework.integration.config.ConsumerEndpointFactoryBean#0
2024-05-23 13:45:23.476 INFO 75598 --- [ restartedMain] o.s.i.mail.ImapIdleChannelAdapter : started imap2Flow.mail:imap-idle-channel-adapter#0
DEBUG: JavaMail version 1.6.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresized: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: peek
DEBUG IMAP: closeFoldersOnStoreFailure
2024-05-23 13:45:23.521 INFO 75598 --- [ restartedMain] c.enterprise.project.Application : Started Application in 8.583 seconds (JVM running for 9.101)
DEBUG IMAP: protocolConnect returning false, host=outlook.office365.com, user=******, password=<null><- I dont understand this log.
2024-05-23 13:45:24.470 INFO 75598 --- [ scheduling-1] c.d.l.c.builder.IntegrationFlowBuilder : Authentication launched with token *****
DEBUG IMAP: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [XXXXXXXX]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: XOAUTH2
DEBUG IMAP: protocolConnect login, host=outlook.office365.com, [email protected], password=<non-null>
A1 AUTHENTICATE XOAUTH2 ***************
A1 OK AUTHENTICATE completed.
My message handler is based on something like this. After the messaging processing, I close the folder as I have defined .autoCloseFolder(false)
public abstract class CustomMessageHandler implements MessageHandler {
private static final Logger logger = LoggerFactory.getLogger(CustomMessageHandler.class);
@Override
public void handleMessage(Message<?> message) throws MessagingException {
this.logger.debug("Start processing message");
try {
processMessage(message);
} catch(MessageProcessingException e) {
logger.error(e.getMessage());
} catch(Exception ex) {
logger.error(ex.getMessage());
} finally {
closeFolder(message);
}
this.logger.debug("End processing message");
}
public abstract void processMessage(Message<?> message) throws MessageProcessingException;
private void closeFolder(Message<?> message) {
Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(message);
if(closeableResource != null) {
try {
closeableResource.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
And the implementation of the handler:
public class ComplexMessageHandler extends CustomMessageHandler {
private static final Logger logger = LoggerFactory.getLogger(ComplexMessageHandler.class);
@Override
public void processMessage(Message<?> message) throws MessageProcessingException {
logger.info("Start complex message processing");
try {
if(message.getPayload() instanceof javax.mail.Message) {
javax.mail.Message emailMessage = (javax.mail.Message)message.getPayload();
String subject = emailMessage.getSubject();
String content = getTextFromMessage(emailMessage);
logger.info("Received email with subject: " + subject);
logger.info("Email content: " + content);
}
} catch(MessagingException | IOException e) {
e.printStackTrace();
throw new MessageProcessingException("Error processing complex message");
} finally {
logger.info("End complex message processing");
}
}
private String getTextFromMessage(javax.mail.Message message) throws MessagingException, IOException {
Object content = message.getContent();
if(content instanceof String) {
return (String)content;
}
else if(content instanceof Multipart) {
Multipart multipart = (Multipart)content;
return getTextFromMultipart(multipart);
}
return "";
}
private String getTextFromMultipart(Multipart multipart) throws MessagingException, IOException {
StringBuilder text = new StringBuilder();
for(int i = 0; i < multipart.getCount(); i++) {
Part part = multipart.getBodyPart(i);
if(part.getContent() instanceof String) {<-If autoclose is true this retrieves an error
text.append(part.getContent());
}
else if(part.getContent() instanceof Multipart) {
text.append(getTextFromMultipart((Multipart)part.getContent()));
}
}
return text.toString();
}
}
Everything is going Ok and the process is processing the incoming mails correctly until the process hungs up and stops processing the incoming messages. The last IMAP debug logs I can see are:
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: XOAUTH2
A3 LIST "" INBOX
* LIST (Marked HasNoChildren) "/" INBOX
A3 OK LIST completed.
DEBUG IMAP: connection available -- size: 1
A4 SELECT INBOX
* 169 EXISTS
* 0 RECENT
* FLAGS (Seen Answered Flagged Deleted Draft $MDNSent)
* OK [PERMANENTFLAGS (Seen Answered Flagged Deleted Draft $MDNSent)] Permanent flags
* OK [UIDVALIDITY 14] UIDVALIDITY value
* OK [UIDNEXT 620] The next unique identifier value
A4 OK [READ-WRITE] SELECT completed.
A5 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL
* SEARCH
A5 OK SEARCH completed.
A6 IDLE
+ IDLE accepted, awaiting DONE command.
DEBUG IMAP: startIdle: set to IDLE
DEBUG IMAP: startIdle: return true
It doesn’t return any exceptions or imap logs until I force the stop of the process. After stopping manually the process the outcomming error launches:
javax.mail.FolderClosedException: * BYE JavaMail Exception: javax.net.ssl.SSLException: Connection reset
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3316) ~[javax.mail-1.6.2.jar:1.6.2]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3159) ~[javax.mail-1.6.2.jar:1.6.2]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3111) ~[javax.mail-1.6.2.jar:1.6.2]
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:197) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:277) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:249) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
2024-05-23 14:16:45.775 WARN 75598 --- [ scheduling-1] o.s.i.mail.ImapIdleChannelAdapter : Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.
java.lang.IllegalStateException: Failure in 'idle' task. Will resubmit.
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:295) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:249) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
Caused by: javax.mail.FolderClosedException: * BYE JavaMail Exception: javax.net.ssl.SSLException: Connection reset
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3316) ~[javax.mail-1.6.2.jar:1.6.2]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3159) ~[javax.mail-1.6.2.jar:1.6.2]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3111) ~[javax.mail-1.6.2.jar:1.6.2]
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:197) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:277) ~[spring-integration-mail-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 10 common frames omitted
DEBUG IMAP: IMAPStore cleanup, force false
To have more info about the error, I have enabled the SSL logs with:
System.setProperty("javax.net.debug", "ssl");
After the previous logs I can see this SSL logs:
javax.net.ssl|WARNING|19|scheduling-1|2024-05-23 12:16:45.768 UTC|SSLSocketImpl.java:1565|handling exception (
"throwable" : {
java.net.SocketException: Connection reset
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:478)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:472)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1364)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:973)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:126)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:103)
at com.sun.mail.iap.Response.<init>(Response.java:133)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:60)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:412)
at com.sun.mail.imap.protocol.IMAPProtocol.readIdleResponse(IMAPProtocol.java:3212)
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3251)
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3159)
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3111)
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:197)
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:277)
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:249)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)}
)
javax.net.ssl|ERROR|19|scheduling-1|2024-05-23 12:16:45.768 UTC|TransportContext.java:341|Fatal (UNEXPECTED_MESSAGE): Connection reset (
"throwable" : {
java.net.SocketException: Connection reset
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:478)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:472)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1364)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:973)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:126)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:103)
at com.sun.mail.iap.Response.<init>(Response.java:133)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:60)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:412)
at com.sun.mail.imap.protocol.IMAPProtocol.readIdleResponse(IMAPProtocol.java:3212)
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3251)
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3159)
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3111)
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:197)
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:277)
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:249)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)}
)
javax.net.ssl|WARNING|19|scheduling-1|2024-05-23 12:16:45.769 UTC|TransportContext.java:383|Fatal: failed to send fatal alert UNEXPECTED_MESSAGE (
"throwable" : {
java.net.SocketException: Tubería rota (Write failed)
at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
at java.base/sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:380)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:292)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:287)
at java.base/sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1591)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:989)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:126)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:103)
at com.sun.mail.iap.Response.<init>(Response.java:133)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:60)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:412)
at com.sun.mail.imap.protocol.IMAPProtocol.readIdleResponse(IMAPProtocol.java:3212)
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3251)
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3159)
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3111)
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:197)
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:277)
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:249)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)}
)
javax.net.ssl|DEBUG|19|scheduling-1|2024-05-23 12:16:45.770 UTC|SSLSocketImpl.java:1638|close the underlying socket
javax.net.ssl|DEBUG|19|scheduling-1|2024-05-23 12:16:45.770 UTC|SSLSocketImpl.java:1657|close the SSL connection (initiative)
DEBUG IMAP: IMAPStore cleanup done
2024-05-23 14:16:45.778 INFO 75598 --- [ Thread-5] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
2024-05-23 14:16:45.806 INFO 75598 --- [ Thread-5] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-05-23 14:16:45.809 INFO 75598 --- [ Thread-5] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2024-05-23 14:16:45.812 INFO 75598 --- [ Thread-5] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
I cant figure out what’s happening and why the process is freezing and staying as a zombie and how can I change my code to avoid it.
The tricky part is that I have launched the code at home and it works correctly less than an hour. If I launch it at my office, the code runs for hours without any problem (I left it 8 hours running), when the token is expired, it takes a new one and all emails that enter in [email protected] are perfectly processed.
Any idea of what’s going on?
My pom dependencies are:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/>
</parent>
.........
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mail</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>