Rob Fellows created NIFI-15868:
----------------------------------

             Summary: Stop connector API response returns stale 
availableActions; DRAIN_FLOWFILES reported not-allowed even when queues have 
data
                 Key: NIFI-15868
                 URL: https://issues.apache.org/jira/browse/NIFI-15868
             Project: Apache NiFi
          Issue Type: Bug
          Components: Core Framework
            Reporter: Rob Fellows


When stopping a connector via {{PUT /nifi-api/connectors/\{id}/run-status}} 
with state {{{}STOPPED{}}}, the response {{ConnectorEntity.availableActions}} 
reports {{DRAIN_FLOWFILES}} (and {{{}PURGE_FLOWFILES{}}}, {{{}DELETE{}}}) as 
{{allowed=false}} with reason {{{}"Connector must be stopped"{}}}, even when 
flowfiles are queued. A follow-up {{GET /nifi-api/connectors/\{id}}} returns 
the same connector with {{{}DRAIN_FLOWFILES.allowed=true{}}}. UIs that rely on 
the stop response to enable/disable actions therefore show DRAIN as disabled 
until the user manually refreshes.

Root cause {{StandardConnectorNode.stop(FlowEngine)}} is asynchronous: it sets 
{{{}desiredState=STOPPED{}}}, transitions {{currentState}} to {{{}STOPPING{}}}, 
schedules the actual stop on the lifecycle executor, and returns a 
{{Future<Void>}} immediately. {{StandardConnectorDAO.stopConnector(String)}} 
discards that future, so {{StandardNiFiServiceFacade.scheduleConnector(...)}} 
builds the response DTO while the connector's {{currentState}} is still 
{{{}STOPPING{}}}. {{getAvailableActions()}} keys off {{isStopped()}} (which 
requires {{{}currentState == STOPPED{}}}), so {{DRAIN_FLOWFILES}} is computed 
as not-allowed for the response.

Steps to reproduce
 # Start a running connector that has flowfiles queued in its internal process 
group.
 # From the connector canvas, stop the connector and capture the response of 
{{{}PUT /nifi-api/connectors/\{id}/run-status{}}}.
 # Observe {{availableActions}} for {{DRAIN_FLOWFILES}} — {{{}allowed: 
false{}}}, {{{}reason: "Connector must be stopped"{}}}.
 # Reload the page (or call {{{}GET /nifi-api/connectors/\{id}{}}}) — 
{{DRAIN_FLOWFILES}} is now {{{}allowed: true{}}}.

Expected The 200 response from the stop call reflects the post-stop state, so 
{{availableActions}} matches what a follow-up GET would return.

Affected code
 * {{StandardNiFiServiceFacade.scheduleConnector}} (~line 3674)
 * {{StandardConnectorDAO.stopConnector}} (~line 133)
 * {{StandardConnectorRepository.stopConnector}} (~line 478)
 * {{StandardConnectorNode.stop}} (~line 433); state transitions to {{STOPPED}} 
only inside {{stopComponent}} (~line 589)
 * {{StandardConnectorNode.getAvailableActions}} / {{isStopped}} (~lines 1145, 
1164)


{*}Related{*}: start path has the same async pattern but is benign 
{{StandardConnectorDAO.startConnector}} is also fire-and-forget and the 
response is built while the connector is in {{STARTING}} (not {{{}RUNNING{}}}). 
The {{availableActions}} for {{STARTING}} happen to match those for {{RUNNING}} 
because {{createStopAction}} explicitly treats {{STARTING}} like {{RUNNING}} 
({{{}StandardConnectorNode.java{}}}, line ~1201). The only user-visible 
artifact is that {{component.state}} briefly reports {{STARTING}} in the start 
response. The stop path does not have an analogous "treat {{STOPPING}} as 
{{{}STOPPED{}}}" branch, which is why DRAIN/PURGE/DELETE come back wrongly 
disabled. The cleanest fix — having {{scheduleConnector}} await the lifecycle 
{{Future}} before serializing the response — would correct both paths 
consistently.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to