ops4j / org.ops4j.pax.cdi

Contexts and Dependency Injection for OSGi
Apache License 2.0
34 stars 26 forks source link

Invalid BundleState exception when stopping bundle [PAXCDI-228] #271

Closed ops4j-issues closed 7 years ago

ops4j-issues commented 8 years ago

Pavel Turkish created PAXCDI-228

I use jetty 9.3.11.v20160721 , pax-cdi 1.0.0.RC1, pax-web 4.2.7 and weld 2.2.11.Final. The problem appears when I stop bundle.

This is the exception I get:

ERROR: Bundle com.example.site.fend [63] EventDispatcher: Error during dispatch. (java.lang.IllegalStateException: Invalid BundleContext.)
java.lang.IllegalStateException: Invalid BundleContext.
    at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:511)
    at org.apache.felix.framework.BundleContextImpl.getBundle(BundleContextImpl.java:114)
    at org.ops4j.pax.cdi.extension.impl.compat.Osgi6ServiceObjectsWrapper.init(Osgi6ServiceObjectsWrapper.java:56)
    at org.ops4j.pax.cdi.extension.impl.compat.OsgiScopeUtils.createServiceObjectsWrapper(OsgiScopeUtils.java:59)
    at org.ops4j.pax.cdi.extension.impl.ServiceEventBridge.serviceChanged(ServiceEventBridge.java:73)
    at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:991)
    at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:839)
    at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:546)
    at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4557)
    at org.apache.felix.framework.Felix.access$000(Felix.java:106)
    at org.apache.felix.framework.Felix$1.serviceChanged(Felix.java:420)
    at org.apache.felix.framework.ServiceRegistry.unregisterService(ServiceRegistry.java:170)
    at org.apache.felix.framework.ServiceRegistrationImpl.unregister(ServiceRegistrationImpl.java:144)
    at org.apache.felix.framework.ServiceRegistry.unregisterServices(ServiceRegistry.java:235)
    at org.apache.felix.framework.Felix.stopBundle(Felix.java:2635)
    at org.apache.felix.framework.BundleImpl.stop(BundleImpl.java:1038)
    at org.apache.felix.framework.BundleImpl.stop(BundleImpl.java:1024)

After long investigation I found out (as I think) that the problem was in org.ops4j.pax.cdi.extension.impl.BeanBundleImpl. This code is never called:

    @PreDestroy
    public void onDestroy() {
        log.debug("onDestroy {}", bundleContext.getBundle());
        componentLifecycleManager.stop();
        serviceEventBridge.stop();
    }

And therefore serviceEventBridge is never stops.


Affects: 1.0.0.RC1 Votes: 0, Watches: 1