Sönke Liebau created NIFI-16294:
-----------------------------------

             Summary: NPE in SiteToSiteStatusReportingTask when root flow is 
unavailable
                 Key: NIFI-16294
                 URL: https://issues.apache.org/jira/browse/NIFI-16294
             Project: Apache NiFi
          Issue Type: Bug
    Affects Versions: 2.11.0
         Environment: Observed when running 2.9.0 on Kubernetes, but 
objectively unrelated to the environment.
            Reporter: Sönke Liebau
            Assignee: Sönke Liebau


We recently encountered infrequent NullPointerExceptions when using the 
SiteToSiteStatusReportingTask in NiFi. We looked at the code and investigated 
in the cluster and usually those Exceptions correlated to cluster nodes 
restarting and rejoining the cluster.
{code:java}
SiteToSiteStatusReportingTask[id=xxx] Error running task 
SiteToSiteStatusReportingTask[id=xxx]: java.lang.NullPointerException
{code}
*Other issues*
NIFI-7105 sounds very similar to this, but is not in fact related.

*Root cause*
We think we found the root cause and a possible fix, I'll open a PR to 
facilitate discussion on the code as well soon.

The SiteToSiteStatusReportingTask calls 
context.getEventAccess().getControllerStatus() in 
[onTrigger|https://github.com/apache/nifi/blob/f5e20e3687f3eee9fecb3a6b59a5b542390616ef/nifi-extension-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteStatusReportingTask.java#L126],
 which returns
null when the root process group isn't available (e.g. during startup before 
the flow is fully initialized, or when nodes join).

The line immediately following that line guards against `null` when retrieving 
the name, but [further 
down|https://github.com/apache/nifi/blob/f5e20e3687f3eee9fecb3a6b59a5b542390616ef/nifi-extension-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteStatusReportingTask.java#L146]
 the result of getControllerStatus is passed on directly to deserialization, 
which throws an Exception in the case of `null`.

*Fix*
For a potential fix I looked at the 
[SiteToSiteMetricsReportingTask|https://github.com/apache/nifi/blob/f5e20e3687f3eee9fecb3a6b59a5b542390616ef/nifi-extension-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteMetricsReportingTask.java#L160]
 , which already guards against `null` and skips execution in that case

Something similar should be done in the StatusReporting task to skip the 
trigger, when the status cannot be retrieved.

I'm happy to open a PR to discuss directly on the code.



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

Reply via email to