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

ASF GitHub Bot commented on FELIX-6036:
---------------------------------------

GitHub user tjwatson opened a pull request:

    https://github.com/apache/felix/pull/170

    FELIX-6036 - avoid stashing stale RefPair objects in OpenStatus

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/tjwatson/felix fixSCR-6036

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/felix/pull/170.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #170
    
----
commit 072aa9539a9ce1636304ee25e4b1fc598959a393
Author: Tom Watson <tjwatson@...>
Date:   2019-01-24T16:46:13Z

    FELIX-6036 - avoid stashing stale RefPair objects in OpenStatus

----


> Race condition prevents optional/greedy ref setter method from being called
> ---------------------------------------------------------------------------
>
>                 Key: FELIX-6036
>                 URL: https://issues.apache.org/jira/browse/FELIX-6036
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>    Affects Versions: scr-2.1.14
>            Reporter: Brent Daniel
>            Priority: Major
>
> I have a component with an optional/dynamic/greedy reference. The target is 
> registered directly with OSGi using BundleContext.registerService(). 
> Normally, either SingleDynamicCustomizer.addedService() or 
> SingleComponentManager.createImplementationObject() will succeed in binding 
> the reference, but there is a race condition that can prevent the setter 
> method from ever being called. 
>  
> The failure path is as follows:
> 1) SingleComponentManager.createImplementationObject calls open() on each of 
> its DependencyManagers. This generates an OpenStatus where the RefPair list 
> is empty because our target has not been registered yet. 
> 2) Before createImplementationObject() can set the component context, the 
> customizer's addedService() method is called in response to the target 
> service registration. It attempts to bind the target service, but that will 
> not happen because the component context has not been set yet. 
> 3) createImplementationObject then creates the implementation, sets the 
> component context, and goes through the list of OpenStatus objects to bind 
> target services. The RefPair list for the OpenStatus object will still be 
> empty, so we will not call the setter method for the reference we're 
> concerned about. 
>  
> I'm not sure of a good way to fix this. I couldn't come up with a good 
> approach using synchronization or earlier creation of the implementation 
> object. At the moment I am working around this by refreshing the list of 
> RefPairs in the OpenStatus object at the top of 
> DependencyManager.bindDependency():
>  
> {code:java}
> // Refresh ref list before binding
> synchronized(m_tracker.tracked()) {
>    status.refs=m_customizer.getRefs(status.trackingCount);
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to