Pierre De Rop created FELIX-6884:
------------------------------------

             Summary: Service.ranking change leaves required dependency 
available
                 Key: FELIX-6884
                 URL: https://issues.apache.org/jira/browse/FELIX-6884
             Project: Felix
          Issue Type: Bug
          Components: Dependency Manager
            Reporter: Pierre De Rop


When a service tracked by a DependencyManager service dependency modifies its 
{{service.ranking}} property, the component's internal list of dependency 
events becomes inconsistent. A stale entry can remain after all the services 
have been unregistered, so a required dependency is still considered available 
although no provider exists.

h3. Example

{code:java}
public interface S {}

public class Consumer {
    void start() { System.out.println("started"); }
    void stop()  { System.out.println("stopped"); }
}

public class Activator extends DependencyActivatorBase {
    @Override
    public void init(BundleContext bc, DependencyManager dm) {
        // Consumer requires one S
        dm.add(createComponent()
            .setImplementation(Consumer.class)
            
.add(createServiceDependency().setService(S.class).setRequired(true)));

        // Two providers with the same ranking (A is registered first: lower 
service.id)
        Dictionary<String, Object> propsA = new Hashtable<>();
        propsA.put(Constants.SERVICE_RANKING, 0);
        ServiceRegistration<S> regA = bc.registerService(S.class, new S() {}, 
propsA);

        Dictionary<String, Object> propsB = new Hashtable<>();
        propsB.put(Constants.SERVICE_RANKING, 0);
        ServiceRegistration<S> regB = bc.registerService(S.class, new S() {}, 
propsB);
        // "started" is printed

        // A changes its ranking
        propsA.put(Constants.SERVICE_RANKING, -10);
        regA.setProperties(propsA);

        // Both providers go away
        regA.unregister();
        regB.unregister();
    }
}
{code}

h3. Actual behavior

* {{stop}} is never called: after both services are unregistered, the required 
dependency is still reported as available and the Consumer component stays 
active, without any S service in the registry.
* The dependency can hand out an event for a service which has already been 
released.
* The service object of A is never released (no {{ungetService}}) and stays 
referenced.

The problem depends on the relative ordering of the tracked services, so it 
does not occur for every combination of rankings (in a simulation using the 
same ordering as {{ServiceReference}}, 21 out of 40 tested combinations leave a 
stale entry).

h3. Expected behavior

* After a ranking change, the dependency keeps tracking exactly the services 
that are registered.
* Once all the services are unregistered, the required dependency is 
unavailable, the Consumer component is deactivated ({{stop}} is called), and 
all the service objects are released.



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

Reply via email to