[ 
https://issues.apache.org/jira/browse/NIFI-16649?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Vincenzo Lombardo updated NIFI-16649:
-------------------------------------
    Status: Patch Available  (was: Open)

> ConsumeIMAP and ConsumePOP3 lose queued messages on OAuth token refresh and 
> fail on stop before first trigger
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: NIFI-16649
>                 URL: https://issues.apache.org/jira/browse/NIFI-16649
>             Project: Apache NiFi
>          Issue Type: Bug
>            Reporter: Vincenzo Lombardo
>            Assignee: Vincenzo Lombardo
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> AbstractEmailProcessor (ConsumeIMAP, ConsumePOP3) has the following lifecycle 
> issues, verified on 2.13.0 and main:
> 1. OAuth2 token refresh rebuilds the receiver on every trigger and drops 
> queued messages
> isAccessTokenRefreshRequired() compares currentAccessToken with 
> OAuth2AccessTokenProvider.getAccessDetails(),
> but currentAccessToken is only assigned in onScheduled(). AccessToken does 
> not override equals(), so once the
> provider returns a refreshed token, the check stays true for every subsequent 
> trigger. On each trigger
> initializeIfNecessary() then:
> - builds a new mail receiver without destroying the previous one, leaking 
> connections
> - replaces messageQueue with a new empty queue, discarding messages already 
> received
> Messages in the queue have already been processed by the Spring receiver, 
> which applies the configured
> SEEN/DELETED flags during receive(). Discarding them means they are never 
> transferred and are not
> received again from the server. With Fetch Size N, up to N-1 messages can be 
> lost on every trigger
> after the first token refresh.
> 2. NullPointerException in onStopped() when the processor never triggered
> messageQueue is created in initializeIfNecessary() on the first trigger. If 
> the processor is stopped before
> that (or before the first successful initialization), 
> flushRemainingMessages() dereferences a null queue.
> The exception escapes onStopped() before messageReceiver.destroy() and before 
> the scheduled executor is shut
> down, so the MailReceiver thread is also leaked.
> Proposed fix:
> - Update currentAccessToken when the receiver is rebuilt for a token refresh
> - Destroy the previous receiver before building a new one
> - Retain queued messages when the receiver is rebuilt
> - Make onStopped() null-safe and always release the receiver and executor



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to