[ 
https://issues.apache.org/jira/browse/FELIX-6882?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pierre De Rop resolved FELIX-6882.
----------------------------------
      Assignee: Pierre De Rop
    Resolution: Fixed

> Component stop() blocks forever if registerService fails with a 
> RuntimeException
> --------------------------------------------------------------------------------
>
>                 Key: FELIX-6882
>                 URL: https://issues.apache.org/jira/browse/FELIX-6882
>             Project: Felix
>          Issue Type: Bug
>          Components: Dependency Manager
>            Reporter: Pierre De Rop
>            Assignee: Pierre De Rop
>            Priority: Major
>
> When a component registers a service, {{ComponentImpl.registerService()}} 
> creates a {{ServiceRegistrationImpl}} wrapper, then computes the service 
> properties ({{calculateServiceProperties()}}) outside of the {{try}} block. 
> Only {{IllegalArgumentException}} is caught. If anything else is thrown (for 
> example the {{IllegalStateException("Could not invoke callback")}} raised by 
> {{ServiceDependencyImpl.getProperties()}} when a {{setPropagate(instance, 
> method)}} callback fails, or an {{IllegalStateException}} from an invalid 
> {{BundleContext}}), the wrapper is never filled in or marked as illegal.
> The component is then reported as registered although no service exists. When 
> it is stopped, {{unregisterService()}} calls 
> {{ServiceRegistrationImpl.unregister()}}, which blocks forever in 
> {{ensureRegistration()}} ({{wait()}} without end). In a real bundle, this 
> freezes {{DependencyActivatorBase.stop()}}, hence the bundle stop. Any user 
> code touching the injected {{ServiceRegistration}} (even 
> {{hashCode()}}/{{toString()}}) also blocks.
> h3. Example
> {code:java}
> public class Activator extends DependencyActivatorBase {
>     public void init(BundleContext ctx, DependencyManager dm) {
>         Component c = createComponent()
>             .setInterface(MyService.class.getName(), null)
>             .setImplementation(MyServiceImpl.class)
>             .add(createServiceDependency()
>                 .setService(OtherService.class)
>                 .setRequired(true)
>                 .setPropagate(this, "props")); // "props" throws a 
> RuntimeException
>         dm.add(c);
>     }
>     Dictionary<String, Object> props(ServiceReference<?> ref) {
>         throw new RuntimeException("boom");
>     }
> }
> {code}
> # Start the bundle and register an {{OtherService}}: the registration of 
> {{MyService}} fails.
> # Stop the bundle (or call {{dm.remove(c)}}): the thread hangs forever in 
> {{ServiceRegistrationImpl.ensureRegistration()}}.
> *Expected*: the failure is logged, the wrapper is set to an illegal state, 
> and stop completes normally.



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

Reply via email to