eclipse-archived / concierge

Eclipse Concierge™ project
https://www.eclipse.org/concierge/
Eclipse Public License 1.0
33 stars 22 forks source link

Deadlock on resolving bundles within a bundle tracker #31

Closed sjsf closed 7 years ago

sjsf commented 7 years ago

Resolving bundles within a bundle tracker apparently leads to a deadlock on the main thread:

"main" #1 prio=5 os_prio=31 tid=0x00007fe20b006800 nid=0x1b03 waiting on condition [0x000070000fd7c000]
   java.lang.Thread.State: TIMED_WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x0000000779608320> (a java.util.concurrent.CountDownLatch$Sync)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1328)
    at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:277)
    at org.apache.felix.scr.impl.Activator$ScrExtension.destroy(Activator.java:193)
    at org.apache.felix.utils.extender.AbstractExtender$2.run(AbstractExtender.java:290)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.felix.utils.extender.AbstractExtender.destroyExtension(AbstractExtender.java:312)
    at org.apache.felix.utils.extender.AbstractExtender.bundleChanged(AbstractExtender.java:186)
    at org.eclipse.concierge.Concierge.notifyBundleListeners(Concierge.java:3685)
    at org.eclipse.concierge.Concierge.notifyBundleListeners(Concierge.java:3620)
    at org.eclipse.concierge.BundleImpl$Revision.markResolved(BundleImpl.java:2133)
    at org.eclipse.concierge.Concierge$ResolverImpl.resolveResource(Concierge.java:3291)
    at org.eclipse.concierge.Concierge$ResolverImpl.resolve0(Concierge.java:2879)
    at org.eclipse.concierge.Concierge.resolve(Concierge.java:2509)
    - locked <0x00000006c032ed78> (a org.eclipse.concierge.Concierge)
    at org.eclipse.concierge.Concierge.resolveBundles(Concierge.java:2272)
    at org.eclipse.concierge.compat.packageadmin.PackageAdminImpl.resolveBundles(PackageAdminImpl.java:223)
    at org.eclipse.smarthome.automation.internal.core.provider.HostFragmentMappingUtil.fillHostFragmentMapping(HostFragmentMappingUtil.java:70)
    at org.eclipse.smarthome.automation.internal.core.provider.AutomationResourceBundlesTracker.addingBundle(AutomationResourceBundlesTracker.java:187)
    at org.eclipse.smarthome.automation.internal.core.provider.AutomationResourceBundlesTracker.addingBundle(AutomationResourceBundlesTracker.java:1)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:467)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:414)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
    at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:156)
    at org.eclipse.smarthome.automation.internal.core.provider.AutomationResourceBundlesTracker.activate(AutomationResourceBundlesTracker.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:231)
    at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:39)
    at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:624)
    at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:508)
    at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:149)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:315)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:127)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:871)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:838)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:850)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:419)
    at org.apache.felix.scr.impl.config.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:376)
    at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:172)
    at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:120)
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:258)
    at org.apache.felix.scr.impl.Activator.access$000(Activator.java:45)
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:185)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:479)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:414)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:443)
    at org.eclipse.concierge.Concierge.notifyBundleListeners(Concierge.java:3685)
    at org.eclipse.concierge.Concierge.notifyBundleListeners(Concierge.java:3620)
    at org.eclipse.concierge.BundleImpl.activate0(BundleImpl.java:586)
    at org.eclipse.concierge.BundleImpl.activate(BundleImpl.java:552)
    - locked <0x0000000779308270> (a org.eclipse.concierge.BundleImpl)
    at org.eclipse.concierge.BundleImpl.start(BundleImpl.java:506)
    at org.eclipse.concierge.BundleImpl.start(BundleImpl.java:444)
    at org.eclipse.concierge.compat.service.XargsFileLauncher.processXargsInputStream(XargsFileLauncher.java:183)
    at org.eclipse.concierge.compat.service.XargsFileLauncher.processXargsFile(XargsFileLauncher.java:83)
    at org.eclipse.concierge.Concierge.doMain(Concierge.java:606)
    at org.eclipse.concierge.Concierge.main(Concierge.java:525)

For details, see https://github.com/eclipse/smarthome-packaging-sample/issues/13#issuecomment-335803723.

sjsf commented 7 years ago

Oh well, on a second look it's actually rather Felix SCR which gets lured into the deadlock. Sorry for the noise...

rellermeyer commented 7 years ago

Thanks for the report and the analysis. Do you think it is a Felix SCR problem or does it run fine on Felix and deadlocks on Concierge (in which case it still could be a bug on our side)?

sjsf commented 7 years ago

Honestly, I have no idea yet whether it's the concrete Felix SCR version which is prone to this error or if it is the way how Concierge is calling it. In any case, I have never seen this in neither with Equinox nor on Karaf (which is using Equinox under the hood too, if I'm not mistaken). Both are OSGi R6 and therefore are using Felix SCR 2.0.x while in Concierge I was using the R5 compatible 1.8.x.

I will let you know once I find out more.

rellermeyer commented 7 years ago

Thanks, I appreciate it.

sjsf commented 7 years ago

One observation: with Concierge R6 (commit f997291f) it works nicely with either of the Felix SCR versions (1.8.4 & 2.0.12) .

maggu2810 commented 7 years ago

Karaf (which is using Equinox under the hood too, if I'm not mistaken).

Karaf supports different OSGi frameworks e.g. Apache Felix and Eclipse Equinox. Default is Apache Felix, AFAIK openHAB changed it to Equinox.

JochenHiller commented 7 years ago

I try to find a test case which can reproduce that behavior using the mentioned versions of Felix SCR. Then we can more easily understand where the root problem is. From the initial stack trace, I see that the whole call chain was started by SCR, starting an ESH bundle with that "strange" way to start bundles from a bundle tracker. The started bundle is using SCR components too, so it feels more than an issue in SCR. But a test case should help to clarify that.