RE: Blocked Thread while shutting down Felix / IPojo

2012-04-03 Thread Gay David (Annecy)
Hi,

Thanks for your analysis Richard, I have open an issue on iPojo
here : https://issues.apache.org/jira/browse/FELIX-3421

It the meantime, I will try to find a workaround to solve my problem.

WBR // David

-Original Message-
From: Richard S. Hall [mailto:he...@ungoverned.org] 
Sent: lundi 2 avril 2012 22:40
To: users@felix.apache.org
Subject: Re: Blocked Thread while shutting down Felix / IPojo

This is not related to FELIX-3393, although it appears related to the 
Aries Blueprint comment on FELIX-3393, which is also unrelated to 
FELIX-3393.

It appears in both situations the component framework (Aries Blueprint 
and/or iPOJO) is synchronously dealing with a bundle being stopped while 
at the same time trying to register a service for that bundle. Since the 
component framework is holding and/or needs its own internal lock when 
dealing with the stopped bundle and registering the service, we get into 
a deadlock situation, since both threads also need the bundle lock too.

Perhaps just open an issue against the framework to track this.

- richard

On 4/2/12 13:46, Gay David (Annecy) wrote:

 Hi,

 I'm currently have a problem with Felix and or IPojo.

 Basically the problem is when Felix is starting up and services are 
 still registering while and in the meantime a stop Felix is request.

 The code to stop is simple : getBundle(0).stop();

 If I have a look at the thread dump on JVisualVM, I have (full thread 
 dump in attachement) :

 FelixStartLevel daemon prio=6 tid=0x06d6c000 nid=0xb00 
 waiting for monitor entry [0x07fbf000]

java.lang.Thread.State: BLOCKED (on object monitor)

 at 
 org.apache.felix.ipojo.IPojoFactory.removeFactoryStateListener(IPojoFactory.java:491)

 - waiting to lock 0xc048c790 (a 
 org.apache.felix.ipojo.ComponentFactory)

 at 
 org.apache.felix.ipojo.InstanceCreator.removeFactory(InstanceCreator.java:187)

 at 
 org.apache.felix.ipojo.Extender.closeManagementFor(Extender.java:156)

 at 
 org.apache.felix.ipojo.Extender.bundleChanged(Extender.java:129)

 at 
 org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)

 at 
 org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)

 at 
 org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)

 at 
 org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4245)

 at 
 org.apache.felix.framework.Felix.stopBundle(Felix.java:2352)

 at 
 org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1215)

 at 
 org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)

 at java.lang.Thread.run(Unknown Source)

Locked ownable synchronizers:

 - None

 And

 Thread-2 daemon prio=6 tid=0x07050800 nid=0x6d8 in 
 Object.wait() [0x084bd000]

java.lang.Thread.State: WAITING (on object monitor)

 at java.lang.Object.wait(Native Method)

 - waiting on 0xc029d238 (a [Ljava.lang.Object;)

 at java.lang.Object.wait(Object.java:485)

 at 
 org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4872)

 - locked 0xc029d238 (a [Ljava.lang.Object;)

 at 
 org.apache.felix.framework.Felix.registerService(Felix.java:3206)

 at 
 org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)

 at 
 org.apache.felix.ipojo.IPojoContext.registerService(IPojoContext.java:338)

 at 
 org.apache.felix.ipojo.handlers.providedservice.ProvidedService.registerService(ProvidedService.java:345)

 - locked 0xeafc8ea0 (a 
 org.apache.felix.ipojo.handlers.providedservice.ProvidedService)

 at 
 org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.__stateChanged(ProvidedServiceHandler.java:494)

 at 
 org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.stateChanged(ProvidedServiceHandler.java)

 at 
 org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:471)

 at 
 org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:353)

 at 
 org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:166)

 at 
 org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:301)

 - locked 0xc048c790 (a 
 org.apache.felix.ipojo.ComponentFactory)

 at 
 org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:238)

 at 
 org.apache.felix.ipojo.Factory$$Proxy.createComponentInstance(Unknown 
 Source

Blocked Thread while shutting down Felix / IPojo

2012-04-02 Thread Gay David (Annecy)
Hi,

I'm currently have a problem with Felix and or IPojo.
Basically the problem is when Felix is starting up and services are still 
registering while and in the meantime a stop Felix is request.
The code to stop is simple : getBundle(0).stop();

If I have a look at the thread dump on JVisualVM, I have (full thread dump in 
attachement) :

FelixStartLevel daemon prio=6 tid=0x06d6c000 nid=0xb00 waiting for 
monitor entry [0x07fbf000]
   java.lang.Thread.State: BLOCKED (on object monitor)
at 
org.apache.felix.ipojo.IPojoFactory.removeFactoryStateListener(IPojoFactory.java:491)
- waiting to lock 0xc048c790 (a 
org.apache.felix.ipojo.ComponentFactory)
at 
org.apache.felix.ipojo.InstanceCreator.removeFactory(InstanceCreator.java:187)
at 
org.apache.felix.ipojo.Extender.closeManagementFor(Extender.java:156)
at 
org.apache.felix.ipojo.Extender.bundleChanged(Extender.java:129)
at 
org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)
at 
org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)
at 
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)
at 
org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4245)
at org.apache.felix.framework.Felix.stopBundle(Felix.java:2352)
at 
org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1215)
at 
org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
- None

And

Thread-2 daemon prio=6 tid=0x07050800 nid=0x6d8 in Object.wait() 
[0x084bd000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on 0xc029d238 (a [Ljava.lang.Object;)
at java.lang.Object.wait(Object.java:485)
at 
org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4872)
- locked 0xc029d238 (a [Ljava.lang.Object;)
at 
org.apache.felix.framework.Felix.registerService(Felix.java:3206)
at 
org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)
at 
org.apache.felix.ipojo.IPojoContext.registerService(IPojoContext.java:338)
at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedService.registerService(ProvidedService.java:345)
- locked 0xeafc8ea0 (a 
org.apache.felix.ipojo.handlers.providedservice.ProvidedService)
at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.__stateChanged(ProvidedServiceHandler.java:494)
at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.stateChanged(ProvidedServiceHandler.java)
at 
org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:471)
at 
org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:353)
at 
org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:166)
at 
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:301)
- locked 0xc048c790 (a 
org.apache.felix.ipojo.ComponentFactory)
at 
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:238)
at 
org.apache.felix.ipojo.Factory$$Proxy.createComponentInstance(Unknown Source)
at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.__createAndStart(ComponentDefinition.java:147)
at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.createAndStart(ComponentDefinition.java)
at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.__validate(ComponentDefinition.java:85)
at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.validate(ComponentDefinition.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown 
Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.ipojo.util.Callback.call(Callback.java:237)
at org.apache.felix.ipojo.util.Callback.call(Callback.java:193)
at 
org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)
at 
org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__stateChanged(LifecycleCallbackHandler.java:162)
at 

Re: Blocked Thread while shutting down Felix / IPojo

2012-04-02 Thread Matias SM
I don't know if that may be your issue but in the book OSGi in action 
[1] they recommend that if a bundle want to stop itself, it should do so 
in a different thread. This is to avoid possible deadlocks if as part of 
the bundle finalization there is any waiting for the calls to finish. 
You can refer to the book's source code examples [2].


HTH, Regards

[1] http://www.manning.com/hall/
[2] 
http://code.google.com/p/osgi-in-action/source/browse/trunk/chapter03/shell-example/org.foo.shell/src/org/foo/shell/StopCommand.java



On 02/04/12 14:46, Gay David (Annecy) wrote:


Hi,

I'm currently have a problem with Felix and or IPojo.

Basically the problem is when Felix is starting up and services are 
still registering while and in the meantime a stop Felix is request.


The code to stop is simple : getBundle(0).stop();

If I have a look at the thread dump on JVisualVM, I have (full thread 
dump in attachement) :


FelixStartLevel daemon prio=6 tid=0x06d6c000 nid=0xb00 
waiting for monitor entry [0x07fbf000]


   java.lang.Thread.State: BLOCKED (on object monitor)

at 
org.apache.felix.ipojo.IPojoFactory.removeFactoryStateListener(IPojoFactory.java:491)


- waiting to lock 0xc048c790 (a 
org.apache.felix.ipojo.ComponentFactory)


at 
org.apache.felix.ipojo.InstanceCreator.removeFactory(InstanceCreator.java:187)


at 
org.apache.felix.ipojo.Extender.closeManagementFor(Extender.java:156)


at 
org.apache.felix.ipojo.Extender.bundleChanged(Extender.java:129)


at 
org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)


at 
org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)


at 
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)


at 
org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4245)


at 
org.apache.felix.framework.Felix.stopBundle(Felix.java:2352)


at 
org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1215)


at 
org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)


at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:

- None

And

Thread-2 daemon prio=6 tid=0x07050800 nid=0x6d8 in 
Object.wait() [0x084bd000]


   java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on 0xc029d238 (a [Ljava.lang.Object;)

at java.lang.Object.wait(Object.java:485)

at 
org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4872)


- locked 0xc029d238 (a [Ljava.lang.Object;)

at 
org.apache.felix.framework.Felix.registerService(Felix.java:3206)


at 
org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)


at 
org.apache.felix.ipojo.IPojoContext.registerService(IPojoContext.java:338)


at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedService.registerService(ProvidedService.java:345)


- locked 0xeafc8ea0 (a 
org.apache.felix.ipojo.handlers.providedservice.ProvidedService)


at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.__stateChanged(ProvidedServiceHandler.java:494)


at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.stateChanged(ProvidedServiceHandler.java)


at 
org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:471)


at 
org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:353)


at 
org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:166)


at 
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:301)


- locked 0xc048c790 (a 
org.apache.felix.ipojo.ComponentFactory)


at 
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:238)


at 
org.apache.felix.ipojo.Factory$$Proxy.createComponentInstance(Unknown 
Source)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.__createAndStart(ComponentDefinition.java:147)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.createAndStart(ComponentDefinition.java)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.__validate(ComponentDefinition.java:85)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.validate(ComponentDefinition.java)


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native 
Method)


at 

Re: Blocked Thread while shutting down Felix / IPojo

2012-04-02 Thread Richard S. Hall
This is not related to FELIX-3393, although it appears related to the 
Aries Blueprint comment on FELIX-3393, which is also unrelated to 
FELIX-3393.


It appears in both situations the component framework (Aries Blueprint 
and/or iPOJO) is synchronously dealing with a bundle being stopped while 
at the same time trying to register a service for that bundle. Since the 
component framework is holding and/or needs its own internal lock when 
dealing with the stopped bundle and registering the service, we get into 
a deadlock situation, since both threads also need the bundle lock too.


Perhaps just open an issue against the framework to track this.

- richard

On 4/2/12 13:46, Gay David (Annecy) wrote:


Hi,

I'm currently have a problem with Felix and or IPojo.

Basically the problem is when Felix is starting up and services are 
still registering while and in the meantime a stop Felix is request.


The code to stop is simple : getBundle(0).stop();

If I have a look at the thread dump on JVisualVM, I have (full thread 
dump in attachement) :


FelixStartLevel daemon prio=6 tid=0x06d6c000 nid=0xb00 
waiting for monitor entry [0x07fbf000]


   java.lang.Thread.State: BLOCKED (on object monitor)

at 
org.apache.felix.ipojo.IPojoFactory.removeFactoryStateListener(IPojoFactory.java:491)


- waiting to lock 0xc048c790 (a 
org.apache.felix.ipojo.ComponentFactory)


at 
org.apache.felix.ipojo.InstanceCreator.removeFactory(InstanceCreator.java:187)


at 
org.apache.felix.ipojo.Extender.closeManagementFor(Extender.java:156)


at 
org.apache.felix.ipojo.Extender.bundleChanged(Extender.java:129)


at 
org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)


at 
org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)


at 
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)


at 
org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4245)


at 
org.apache.felix.framework.Felix.stopBundle(Felix.java:2352)


at 
org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1215)


at 
org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)


at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:

- None

And

Thread-2 daemon prio=6 tid=0x07050800 nid=0x6d8 in 
Object.wait() [0x084bd000]


   java.lang.Thread.State: WAITING (on object monitor)

at java.lang.Object.wait(Native Method)

- waiting on 0xc029d238 (a [Ljava.lang.Object;)

at java.lang.Object.wait(Object.java:485)

at 
org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4872)


- locked 0xc029d238 (a [Ljava.lang.Object;)

at 
org.apache.felix.framework.Felix.registerService(Felix.java:3206)


at 
org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)


at 
org.apache.felix.ipojo.IPojoContext.registerService(IPojoContext.java:338)


at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedService.registerService(ProvidedService.java:345)


- locked 0xeafc8ea0 (a 
org.apache.felix.ipojo.handlers.providedservice.ProvidedService)


at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.__stateChanged(ProvidedServiceHandler.java:494)


at 
org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler.stateChanged(ProvidedServiceHandler.java)


at 
org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:471)


at 
org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:353)


at 
org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:166)


at 
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:301)


- locked 0xc048c790 (a 
org.apache.felix.ipojo.ComponentFactory)


at 
org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:238)


at 
org.apache.felix.ipojo.Factory$$Proxy.createComponentInstance(Unknown 
Source)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.__createAndStart(ComponentDefinition.java:147)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.createAndStart(ComponentDefinition.java)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.__validate(ComponentDefinition.java:85)


at 
com.axway.cmp.ume.ui.internal.ComponentDefinition.validate(ComponentDefinition.java)