You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by "Oleg Zhurakousky (JIRA)" <ji...@apache.org> on 2015/11/11 19:49:11 UTC

[jira] [Commented] (NIFI-1143) Race condition during initialization of ControllerServices

    [ https://issues.apache.org/jira/browse/NIFI-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15000883#comment-15000883 ] 

Oleg Zhurakousky commented on NIFI-1143:
----------------------------------------

Ok, figured out what the problem is, so let me try to describe it.
This was a classic race condition with improper double checking of the dependent service state. Below is the guilty code in PropertyDescriptor
{code}
if (!context.getControllerServiceLookup().isControllerServiceEnabled(serviceId)
                        && !context.getControllerServiceLookup().isControllerServiceEnabling(serviceId)) {
{code}
Assume service have been set into ENABLING state and its enabling task is executing.
The main issue is that the first check asks if the service is ENABLED and would return *false* if it is not. When the second check is performed the service could be promoted to ENABLED which means it will also returns *false*. Thus, the IF statement returns true and validation error is thrown even though the dependent service was perfectly fine and enabled.

Changing the order of checks will solve the issue, but I am encapsulating into a private method with some explanation so it will be easy to read.
{code}
private boolean isDependentServiceEnableable(ValidationContext context, String serviceId) {
    boolean enableable = context.getControllerServiceLookup().isControllerServiceEnabling(serviceId);
    if (!enableable) {
        enableable = context.getControllerServiceLookup().isControllerServiceEnabled(serviceId);
    }
    return enableable;
}
{code} 

> Race condition during initialization of ControllerServices
> ----------------------------------------------------------
>
>                 Key: NIFI-1143
>                 URL: https://issues.apache.org/jira/browse/NIFI-1143
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 0.3.0
>            Reporter: Oleg Zhurakousky
>            Assignee: Oleg Zhurakousky
>             Fix For: 0.4.0
>
>
> While merging NIFI-1061 [~joewitt] and I noticed a strange test failure:
> {code}
> Running org.apache.nifi.controller.service.TestStandardControllerServiceProvider
> Tests run: 6, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.138 sec <<< FAILURE! - in org.apache.nifi.controller.service.TestStandardControllerServiceProvider
> testEnableReferencingServicesGraph(org.apache.nifi.controller.service.TestStandardControllerServiceProvider)  Time elapsed: 0.013 sec  <<< ERROR!
> java.lang.IllegalStateException: ServiceA[id=1] cannot be enabled because it is not valid: []
> at org.apache.nifi.controller.service.StandardControllerServiceNode.verifyCanEnable(StandardControllerServiceNode.java:176)
> at org.apache.nifi.controller.service.StandardControllerServiceProvider.enableControllerService(StandardControllerServiceProvider.java:286)
> at org.apache.nifi.controller.service.StandardControllerServiceProvider.enableReferencingServices(StandardControllerServiceProvider.java:565)
> at org.apache.nifi.controller.service.StandardControllerServiceProvider.enableReferencingServices(StandardControllerServiceProvider.java:544)
> at org.apache.nifi.controller.service.TestStandardControllerServiceProvider.testEnableReferencingServicesGraph(TestStandardControllerServiceProvider.java:141)
> {code}
> At first it was attributed to a small clean up change on _StandardProcessScheduler_ that went in with NIFI-1061. However the failure now is reproducible without the change to  _StandardProcessScheduler_. In fact running the test in repeat mode also produces a variation of a failure seen above:
> {code}
> java.lang.IllegalStateException: ServiceA[id=2] cannot be enabled because it is not valid: 'Other Service' validated against 'ServiceB' is invalid because Controller Service ServiceB[id=4] is disabled
> 	at org.apache.nifi.controller.service.StandardControllerServiceNode.verifyCanEnable(StandardControllerServiceNode.java:194)
> 	at org.apache.nifi.controller.service.StandardControllerServiceProvider.enableReferencingServices(StandardControllerServiceProvider.java:557)
> 	at org.apache.nifi.controller.service.StandardControllerServiceProvider.enableReferencingServices(StandardControllerServiceProvider.java:544)
> 	at org.apache.nifi.controller.service.TestStandardControllerServiceProvider.testEnableReferencingServicesGraph(TestStandardControllerServiceProvider.java:156)
> 	at org.apache.nifi.controller.service.TestStandardControllerServiceProvider.foo(TestStandardControllerServiceProvider.java:119)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	. . .
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)