You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Dan Gravell <el...@googlemail.com> on 2013/03/05 14:15:39 UTC

Shutdown deadlock on OS X while doing AWT stuff

In my OSGi app (running on Felix 4.0.2) I use the Java SystemTray to add
items to the system tray. One of these items is a 'quit' item:

miQuit.addActionListener(new ActionListener() {
@Override
def actionPerformed(e:ActionEvent) {
platform.shutdown();
}
});

Then, PlatformImpl.shutdown does a:

lastContext.getBundle(0).stop();

Where lastContext is the BundleContext for the containing bundle. The
SystemTray code and PlatformImpl are in different bundles. Stopping the
bundles has the effect of calling:

@Deactivate def shutdown() {
awt.SystemTray.getSystemTray.getTrayIcons.foreach(systemTray.remove);
}

This is back on the SystemTray component (I'm using bnd style DS here).

I am seeing a deadlock occur, but fairly infrequently and only on OS X. I
managed to get a stack trace last time. Here are two suspicious looking
threads (I attached the entire thing):

"FelixStartLevel" daemon prio=5 tid=109c2d800 nid=0x10f371000 in
Object.wait() [10f36e000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <7eae23890> (a java.awt.EventQueue$1AWTInvocationLock)
at java.lang.Object.wait(Object.java:485)
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1117)
- locked <7eae23890> (a java.awt.EventQueue$1AWTInvocationLock)
at java.awt.Window.doDispose(Window.java:1036)
at java.awt.Window.dispose(Window.java:974)
at apple.awt.CTrayIconPeer.disposeImpl(CTrayIconPeer.java:58)
at apple.awt.PeerImpl.dispose(PeerImpl.java:30)
at java.awt.TrayIcon.removeNotify(TrayIcon.java:701)
at java.awt.SystemTray.remove(SystemTray.java:273)
- locked <7ed5e5968> (a java.awt.SystemTray)
at
com.elsten.bliss.ui.systemtray.SystemTray$$anonfun$shutdown$1.apply(SystemTray.scala:149)
at
com.elsten.bliss.ui.systemtray.SystemTray$$anonfun$shutdown$1.apply(SystemTray.scala:149)
at
scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)
at com.elsten.bliss.ui.systemtray.SystemTray.shutdown(SystemTray.scala:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
[...]

"AWT-EventQueue-0" prio=6 tid=105d82800 nid=0x11505f000 in Object.wait()
[11505d000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <7ece2ed20> (a org.apache.felix.main.Main$1)
at java.lang.Thread.join(Thread.java:1210)
- locked <7ece2ed20> (a org.apache.felix.main.Main$1)
at java.lang.Thread.join(Thread.java:1263)
at
java.lang.ApplicationShutdownHooks.runHooks(ApplicationShutdownHooks.java:79)
at
java.lang.ApplicationShutdownHooks$1.run(ApplicationShutdownHooks.java:24)
at java.lang.Shutdown.runHooks(Shutdown.java:79)
at java.lang.Shutdown.sequence(Shutdown.java:123)
at java.lang.Shutdown.exit(Shutdown.java:168)
- locked <7faf9e240> (a java.lang.Class for java.lang.Shutdown)
at java.lang.Runtime.exit(Runtime.java:90)
at java.lang.System.exit(System.java:921)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:124)
- locked <7ed6a2420> (a com.apple.eawt._AppEventHandler)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:31)
at
com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:382)
at
com.apple.eawt._AppEventHandler$_AppEventDispatcher$1.run(_AppEventHandler.java:487)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
[...]

Is there something I'm doing incorrectly? It looks like
"_AppEventHandler.performQuit" is calling System.exit... but won't this be
prone to deadlocks with OSGi?

It's possible in this case that I chose to shutdown my app and this is what
sent the event. If this is the case how can I work around this? I'm
guessing that the removal of SystemTray items can't be done in this case,
or has to be done in some managed thread context.

Just wondering if anyone else has seen this.

Dan

Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Dan Gravell <el...@googlemail.com>.
Yeah, it worked. I had to write a dynamic proxy to access the API because
Eclipse complains about access restrictions for com.apple.eawt but once I'd
written the code, exported the package from my system bundle fragment and
imported into the new bundle it all worked fine.

On Tue, Mar 5, 2013 at 5:51 PM, Dan Gravell
<el...@googlemail.com>wrote:

> Thanks everyone. I was unaware of the Apple Application library and so
> I'll create a bundle for OS X which registers its own QuitHandler and see
> if that helps things.
>
> I'll pursue other suggestions afterwards.
>
> Dan
>
>
> On Tue, Mar 5, 2013 at 2:36 PM, Jan Willem Janssen <
> janwillem.janssen@luminis.eu> wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 3/5/13 3:23 PM, Dan Gravell wrote:
>> > Well, I could be explicitly stopping the framework, or the stop
>> > could occur when the OS is shutdown and it *appears* this
>> > com.apple.eawt._AppEventHandler kicks in and calls System.exit...
>> > Does that count as an explicit stop?
>>
>> FWIW: The eawt application-quit hook calls System.exit(0) by default,
>> see [1]. Either set another quit strategy or call
>> QuitResponse#cancelQuit in your QuitHandler.
>>
>> Hope this helps,
>>
>> [1]
>>
>> http://developer.apple.com/library/mac/documentation/Java/Reference/JavaSE6_AppleExtensionsRef/api/com/apple/eawt/QuitStrategy.html
>>
>> - --
>> Met vriendelijke groeten | Kind regards
>>
>> Jan Willem Janssen | Software Architect
>> +31 631 765 814
>>
>> /My world is revolving around PulseOn and Amdatu/
>>
>> Luminis Technologies B.V.
>> J.C. Wilslaan 29
>> 7313 HK   Apeldoorn
>> +31 88 586 46 30
>>
>> http://www.luminis-technologies.com
>> http://www.luminis.eu
>>
>> KvK (CoC) 09 16 28 93
>> BTW (VAT) NL8169.78.566.B.01
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
>> Comment: GPGTools - http://gpgtools.org
>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>>
>> iQIcBAEBAgAGBQJRNgL5AAoJEKF/mP2eHDc4EGsP/iWKEhx/EG9Gmu7iOO9XN05b
>> prFlolILB+STYP3akDBIuaI973H6UFofqdlCAiBcrbJWV2doXYcXzEv7aBIzSCLI
>> uZprA+z2dW9kaWp24QrOtNMH3bTR27a46/WSjiyAVEY3oYo+4GqKUwSzgTy4lFE0
>> P8eH1SzyFTZRwaa1engT8sieiEbgImR6o3GtFJlZqK9D0bBs28lF7U2kJFIvu+er
>> JlerOPwLN4VKe2DZO2iA6gS7NatQTcjXL0tkwmYY890cJhW4/v9RU1VHZOstf2PA
>> bWHN43dAE9J6r9MJY7fOdRx2uOYYM6rhlSZBqPIMMOInRcWHZ0SFuaqMpx9UzK/s
>> ZY0A1GGkZ2o4aNCzyI91CM9xF9w3Q/q+TxH2SUP0xQyTJ3LOWf4GCmwXw5O8rd7H
>> FAJK4ui6Pr98P2kmCWA/9wSrm5xVxuC3/pbzE5pYqT0wXvn00IIvlPF813fIszYC
>> xpL/zsyLt+SPjV/N0HQ1JBVoDZC6u/sGwkbwMbsl2HC79C+hEt1ELBOE5+BHwGW0
>> dOAOn0b5Hkq3tCLzWIdwhuXHpn1fLNcTvoMQ1LbP9pHC0Nh6nz1GbclRTIu8jRMo
>> zGGHJeltYPnGFLdAVUc10Mrq3O9abnWxDa1UB3KXLnr8GkzoGMVqS6/3142V/oTM
>> 8m58tIyf47Z28IxreoGy
>> =FS4a
>> -----END PGP SIGNATURE-----
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>

Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Dan Gravell <el...@googlemail.com>.
Thanks everyone. I was unaware of the Apple Application library and so I'll
create a bundle for OS X which registers its own QuitHandler and see if
that helps things.

I'll pursue other suggestions afterwards.

Dan

On Tue, Mar 5, 2013 at 2:36 PM, Jan Willem Janssen <
janwillem.janssen@luminis.eu> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 3/5/13 3:23 PM, Dan Gravell wrote:
> > Well, I could be explicitly stopping the framework, or the stop
> > could occur when the OS is shutdown and it *appears* this
> > com.apple.eawt._AppEventHandler kicks in and calls System.exit...
> > Does that count as an explicit stop?
>
> FWIW: The eawt application-quit hook calls System.exit(0) by default,
> see [1]. Either set another quit strategy or call
> QuitResponse#cancelQuit in your QuitHandler.
>
> Hope this helps,
>
> [1]
>
> http://developer.apple.com/library/mac/documentation/Java/Reference/JavaSE6_AppleExtensionsRef/api/com/apple/eawt/QuitStrategy.html
>
> - --
> Met vriendelijke groeten | Kind regards
>
> Jan Willem Janssen | Software Architect
> +31 631 765 814
>
> /My world is revolving around PulseOn and Amdatu/
>
> Luminis Technologies B.V.
> J.C. Wilslaan 29
> 7313 HK   Apeldoorn
> +31 88 586 46 30
>
> http://www.luminis-technologies.com
> http://www.luminis.eu
>
> KvK (CoC) 09 16 28 93
> BTW (VAT) NL8169.78.566.B.01
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBAgAGBQJRNgL5AAoJEKF/mP2eHDc4EGsP/iWKEhx/EG9Gmu7iOO9XN05b
> prFlolILB+STYP3akDBIuaI973H6UFofqdlCAiBcrbJWV2doXYcXzEv7aBIzSCLI
> uZprA+z2dW9kaWp24QrOtNMH3bTR27a46/WSjiyAVEY3oYo+4GqKUwSzgTy4lFE0
> P8eH1SzyFTZRwaa1engT8sieiEbgImR6o3GtFJlZqK9D0bBs28lF7U2kJFIvu+er
> JlerOPwLN4VKe2DZO2iA6gS7NatQTcjXL0tkwmYY890cJhW4/v9RU1VHZOstf2PA
> bWHN43dAE9J6r9MJY7fOdRx2uOYYM6rhlSZBqPIMMOInRcWHZ0SFuaqMpx9UzK/s
> ZY0A1GGkZ2o4aNCzyI91CM9xF9w3Q/q+TxH2SUP0xQyTJ3LOWf4GCmwXw5O8rd7H
> FAJK4ui6Pr98P2kmCWA/9wSrm5xVxuC3/pbzE5pYqT0wXvn00IIvlPF813fIszYC
> xpL/zsyLt+SPjV/N0HQ1JBVoDZC6u/sGwkbwMbsl2HC79C+hEt1ELBOE5+BHwGW0
> dOAOn0b5Hkq3tCLzWIdwhuXHpn1fLNcTvoMQ1LbP9pHC0Nh6nz1GbclRTIu8jRMo
> zGGHJeltYPnGFLdAVUc10Mrq3O9abnWxDa1UB3KXLnr8GkzoGMVqS6/3142V/oTM
> 8m58tIyf47Z28IxreoGy
> =FS4a
> -----END PGP SIGNATURE-----
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Jan Willem Janssen <ja...@luminis.eu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 3/5/13 3:23 PM, Dan Gravell wrote:
> Well, I could be explicitly stopping the framework, or the stop
> could occur when the OS is shutdown and it *appears* this
> com.apple.eawt._AppEventHandler kicks in and calls System.exit...
> Does that count as an explicit stop?

FWIW: The eawt application-quit hook calls System.exit(0) by default,
see [1]. Either set another quit strategy or call
QuitResponse#cancelQuit in your QuitHandler.

Hope this helps,

[1]
http://developer.apple.com/library/mac/documentation/Java/Reference/JavaSE6_AppleExtensionsRef/api/com/apple/eawt/QuitStrategy.html

- -- 
Met vriendelijke groeten | Kind regards

Jan Willem Janssen | Software Architect
+31 631 765 814

/My world is revolving around PulseOn and Amdatu/

Luminis Technologies B.V.
J.C. Wilslaan 29
7313 HK   Apeldoorn
+31 88 586 46 30

http://www.luminis-technologies.com
http://www.luminis.eu

KvK (CoC) 09 16 28 93
BTW (VAT) NL8169.78.566.B.01
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRNgL5AAoJEKF/mP2eHDc4EGsP/iWKEhx/EG9Gmu7iOO9XN05b
prFlolILB+STYP3akDBIuaI973H6UFofqdlCAiBcrbJWV2doXYcXzEv7aBIzSCLI
uZprA+z2dW9kaWp24QrOtNMH3bTR27a46/WSjiyAVEY3oYo+4GqKUwSzgTy4lFE0
P8eH1SzyFTZRwaa1engT8sieiEbgImR6o3GtFJlZqK9D0bBs28lF7U2kJFIvu+er
JlerOPwLN4VKe2DZO2iA6gS7NatQTcjXL0tkwmYY890cJhW4/v9RU1VHZOstf2PA
bWHN43dAE9J6r9MJY7fOdRx2uOYYM6rhlSZBqPIMMOInRcWHZ0SFuaqMpx9UzK/s
ZY0A1GGkZ2o4aNCzyI91CM9xF9w3Q/q+TxH2SUP0xQyTJ3LOWf4GCmwXw5O8rd7H
FAJK4ui6Pr98P2kmCWA/9wSrm5xVxuC3/pbzE5pYqT0wXvn00IIvlPF813fIszYC
xpL/zsyLt+SPjV/N0HQ1JBVoDZC6u/sGwkbwMbsl2HC79C+hEt1ELBOE5+BHwGW0
dOAOn0b5Hkq3tCLzWIdwhuXHpn1fLNcTvoMQ1LbP9pHC0Nh6nz1GbclRTIu8jRMo
zGGHJeltYPnGFLdAVUc10Mrq3O9abnWxDa1UB3KXLnr8GkzoGMVqS6/3142V/oTM
8m58tIyf47Z28IxreoGy
=FS4a
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 3/5/13 09:23 , Dan Gravell wrote:
>> How are you launching the framework?
>
> I'm just running felix.jar.

That is the standard Felix launcher.

>
>
>> If you are using the standard Felix launcher, it registers a VM shutdown
>> hook to actually stop the framework which can sometimes cause issues. Since
>> you are explicitly stopping the framework, you could disable the launcher's
>> shutdown hook in conf/config.properties...look in that file and you'll see
>> how to disable it.
>>
> Well, I could be explicitly stopping the framework, or the stop could occur
> when the OS is shutdown and it *appears* this com.apple.eawt._AppEventHandler
> kicks in and calls System.exit... Does that count as an explicit stop?

No, it doesn't. This is what would be triggering the launchers shutdown 
hook.

>
> Note that my reading of the stack trace may not be correct. After all, I
> would've thought someone had noticed this before.

It just depends on whether or not anyone tried to put in a tray icon 
before, I guess.

You might have to mess around a little bit and see if you can come up 
with a different path to remove the tray icon. One thing that is 
certain, is that the VM is in a fairly fragile state when shutdown hooks 
are invoked, which is why we allow ours to be disabled.

Just two thoughts, you could possibly try to register your own shutdown 
hook in your bundle to remove the tray icon (if you are the only app 
running, you don't need to worry about gc'ing it I would imagine). You 
could still potentially disable the launcher's shutdown hook, since I 
don't believe the framework needs to be cleanly shutdown (although some 
framework impls may). Another possibility is to try to synchronously 
listen for the system bundle to start STOPPING and remove the tray icon 
in the event callback.

Not sure if any of this will help or not.

-> richard

>
> Dan
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Dan Gravell <el...@googlemail.com>.
> How are you launching the framework?


I'm just running felix.jar.


> If you are using the standard Felix launcher, it registers a VM shutdown
> hook to actually stop the framework which can sometimes cause issues. Since
> you are explicitly stopping the framework, you could disable the launcher's
> shutdown hook in conf/config.properties...look in that file and you'll see
> how to disable it.
>

Well, I could be explicitly stopping the framework, or the stop could occur
when the OS is shutdown and it *appears* this com.apple.eawt._AppEventHandler
kicks in and calls System.exit... Does that count as an explicit stop?

Note that my reading of the stack trace may not be correct. After all, I
would've thought someone had noticed this before.

Dan

Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 3/5/13 09:02 , Dan Gravell wrote:
> Sorry, 'platform' is my code.
>
> Here's the full listing for platform.shutdown:
>
> public void shutdown() {
> if(null!=main) main.shutdown();
>   if(lastContext!=null) {
> try {
> lastContext.getBundle(0).stop();
> } catch (BundleException e) {
> LOG.error("Failed to stop system bundle, attempting system.exit", e);
> System.exit(0);
> }
> } else {
> LOG.error("Failed to stop system bundle because had no BundleContext");
> System.exit(0);
> }
> }
>
> As far as I can see, "main.shutdown" is not causing any trouble, because if
> @deactivate is being called on my Components,
> lastContext.getBundle(0).stop() must've been called. main.shutdown()
> performs some further shut down code, code that otherwise I guess could be
> part of another @deactivate.
>
> I don't receive any of the log messages.
>
> I'm beginning to wonder if this is just a interoperability problem with
> System.exit being called as a result of system shutdown.

How are you launching the framework? If you are using the standard Felix 
launcher, it registers a VM shutdown hook to actually stop the framework 
which can sometimes cause issues. Since you are explicitly stopping the 
framework, you could disable the launcher's shutdown hook in 
conf/config.properties...look in that file and you'll see how to disable it.

That may or may not help.

-> richard

>
> Dan
>
>
> On Tue, Mar 5, 2013 at 1:54 PM, Ferry Huberts <ma...@hupie.com> wrote:
>
>>
>> On 05/03/13 14:15, Dan Gravell wrote:
>>
>>> In my OSGi app (running on Felix 4.0.2) I use the Java SystemTray to add
>>> items to the system tray. One of these items is a 'quit' item:
>>>
>>> miQuit.addActionListener(new ActionListener() {
>>> @Override
>>> def actionPerformed(e:ActionEvent) {
>>> platform.shutdown();
>>> }
>>> });
>>>
>>> Then, PlatformImpl.shutdown does a:
>>>
>>
>> Why do you delegate to 'platform'.
>> I think you can call bundleContext.getBundle(0).**stop() right there.
>>
>> See if that fixes your deadlock
>> Otherwise try removing the systray items before calling stop.
>>
>>
>>> lastContext.getBundle(0).stop(**);
>>>
>>> Where lastContext is the BundleContext for the containing bundle. The
>>> SystemTray code and PlatformImpl are in different bundles. Stopping the
>>> bundles has the effect of calling:
>>>
>>> @Deactivate def shutdown() {
>>> awt.SystemTray.getSystemTray.**getTrayIcons.foreach(**systemTray.remove);
>>> }
>>>
>>> This is back on the SystemTray component (I'm using bnd style DS here).
>>>
>>> I am seeing a deadlock occur, but fairly infrequently and only on OS X.
>>> I managed to get a stack trace last time. Here are two suspicious
>>> looking threads (I attached the entire thing):
>>>
>>> "FelixStartLevel" daemon prio=5 tid=109c2d800 nid=0x10f371000 in
>>> Object.wait() [10f36e000]
>>>      java.lang.Thread.State: WAITING (on object monitor)
>>> at java.lang.Object.wait(Native Method)
>>> - waiting on <7eae23890> (a java.awt.EventQueue$**1AWTInvocationLock)
>>> at java.lang.Object.wait(Object.**java:485)
>>> at java.awt.EventQueue.**invokeAndWait(EventQueue.java:**1117)
>>> - locked <7eae23890> (a java.awt.EventQueue$**1AWTInvocationLock)
>>> at java.awt.Window.doDispose(**Window.java:1036)
>>> at java.awt.Window.dispose(**Window.java:974)
>>> at apple.awt.CTrayIconPeer.**disposeImpl(CTrayIconPeer.**java:58)
>>> at apple.awt.PeerImpl.dispose(**PeerImpl.java:30)
>>> at java.awt.TrayIcon.**removeNotify(TrayIcon.java:**701)
>>> at java.awt.SystemTray.remove(**SystemTray.java:273)
>>> - locked <7ed5e5968> (a java.awt.SystemTray)
>>> at
>>> com.elsten.bliss.ui.**systemtray.SystemTray$$**anonfun$shutdown$1.apply(*
>>> *SystemTray.scala:149)
>>> at
>>> com.elsten.bliss.ui.**systemtray.SystemTray$$**anonfun$shutdown$1.apply(*
>>> *SystemTray.scala:149)
>>> at
>>> scala.collection.**IndexedSeqOptimized$class.**
>>> foreach(IndexedSeqOptimized.**scala:34)
>>> at scala.collection.mutable.**ArrayOps.foreach(ArrayOps.**scala:38)
>>> at com.elsten.bliss.ui.**systemtray.SystemTray.**
>>> shutdown(SystemTray.scala:149)
>>> at sun.reflect.**NativeMethodAccessorImpl.**invoke0(Native Method)
>>> at
>>> sun.reflect.**NativeMethodAccessorImpl.**invoke(**
>>> NativeMethodAccessorImpl.java:**39)
>>> at
>>> sun.reflect.**DelegatingMethodAccessorImpl.**invoke(**
>>> DelegatingMethodAccessorImpl.**java:25)
>>> at java.lang.reflect.Method.**invoke(Method.java:597)
>>> [...]
>>>
>>> "AWT-EventQueue-0" prio=6 tid=105d82800 nid=0x11505f000 in Object.wait()
>>> [11505d000]
>>>      java.lang.Thread.State: WAITING (on object monitor)
>>> at java.lang.Object.wait(Native Method)
>>> - waiting on <7ece2ed20> (a org.apache.felix.main.Main$1)
>>> at java.lang.Thread.join(Thread.**java:1210)
>>> - locked <7ece2ed20> (a org.apache.felix.main.Main$1)
>>> at java.lang.Thread.join(Thread.**java:1263)
>>> at
>>> java.lang.**ApplicationShutdownHooks.**runHooks(**
>>> ApplicationShutdownHooks.java:**79)
>>> at
>>> java.lang.**ApplicationShutdownHooks$1.**run(ApplicationShutdownHooks.**
>>> java:24)
>>> at java.lang.Shutdown.runHooks(**Shutdown.java:79)
>>> at java.lang.Shutdown.sequence(**Shutdown.java:123)
>>> at java.lang.Shutdown.exit(**Shutdown.java:168)
>>> - locked <7faf9e240> (a java.lang.Class for java.lang.Shutdown)
>>> at java.lang.Runtime.exit(**Runtime.java:90)
>>> at java.lang.System.exit(System.**java:921)
>>> at com.apple.eawt._**AppEventHandler.performQuit(_**
>>> AppEventHandler.java:124)
>>> - locked <7ed6a2420> (a com.apple.eawt._**AppEventHandler)
>>> at com.apple.eawt.QuitResponse.**performQuit(QuitResponse.java:**31)
>>> at
>>> com.apple.eawt._**AppEventHandler$_**QuitDispatcher.**
>>> performDefaultAction(_**AppEventHandler.java:382)
>>> at
>>> com.apple.eawt._**AppEventHandler$_**AppEventDispatcher$1.run(_**
>>> AppEventHandler.java:487)
>>> at java.awt.event.**InvocationEvent.dispatch(**InvocationEvent.java:209)
>>> [...]
>>>
>>> Is there something I'm doing incorrectly? It looks like
>>> "_AppEventHandler.performQuit" is calling System.exit... but won't this
>>> be prone to deadlocks with OSGi?
>>>
>>> It's possible in this case that I chose to shutdown my app and this is
>>> what sent the event. If this is the case how can I work around this? I'm
>>> guessing that the removal of SystemTray items can't be done in this
>>> case, or has to be done in some managed thread context.
>>>
>>> Just wondering if anyone else has seen this.
>>>
>>> Dan
>>>
>>>
>>>
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>> --
>> Ferry Huberts
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Dan Gravell <el...@googlemail.com>.
Sorry, 'platform' is my code.

Here's the full listing for platform.shutdown:

public void shutdown() {
if(null!=main) main.shutdown();
 if(lastContext!=null) {
try {
lastContext.getBundle(0).stop();
} catch (BundleException e) {
LOG.error("Failed to stop system bundle, attempting system.exit", e);
System.exit(0);
}
} else {
LOG.error("Failed to stop system bundle because had no BundleContext");
System.exit(0);
}
}

As far as I can see, "main.shutdown" is not causing any trouble, because if
@deactivate is being called on my Components,
lastContext.getBundle(0).stop() must've been called. main.shutdown()
performs some further shut down code, code that otherwise I guess could be
part of another @deactivate.

I don't receive any of the log messages.

I'm beginning to wonder if this is just a interoperability problem with
System.exit being called as a result of system shutdown.

Dan


On Tue, Mar 5, 2013 at 1:54 PM, Ferry Huberts <ma...@hupie.com> wrote:

>
>
> On 05/03/13 14:15, Dan Gravell wrote:
>
>> In my OSGi app (running on Felix 4.0.2) I use the Java SystemTray to add
>> items to the system tray. One of these items is a 'quit' item:
>>
>> miQuit.addActionListener(new ActionListener() {
>> @Override
>> def actionPerformed(e:ActionEvent) {
>> platform.shutdown();
>> }
>> });
>>
>> Then, PlatformImpl.shutdown does a:
>>
>
>
> Why do you delegate to 'platform'.
> I think you can call bundleContext.getBundle(0).**stop() right there.
>
> See if that fixes your deadlock
> Otherwise try removing the systray items before calling stop.
>
>
>> lastContext.getBundle(0).stop(**);
>>
>> Where lastContext is the BundleContext for the containing bundle. The
>> SystemTray code and PlatformImpl are in different bundles. Stopping the
>> bundles has the effect of calling:
>>
>> @Deactivate def shutdown() {
>> awt.SystemTray.getSystemTray.**getTrayIcons.foreach(**systemTray.remove);
>> }
>>
>> This is back on the SystemTray component (I'm using bnd style DS here).
>>
>> I am seeing a deadlock occur, but fairly infrequently and only on OS X.
>> I managed to get a stack trace last time. Here are two suspicious
>> looking threads (I attached the entire thing):
>>
>> "FelixStartLevel" daemon prio=5 tid=109c2d800 nid=0x10f371000 in
>> Object.wait() [10f36e000]
>>     java.lang.Thread.State: WAITING (on object monitor)
>> at java.lang.Object.wait(Native Method)
>> - waiting on <7eae23890> (a java.awt.EventQueue$**1AWTInvocationLock)
>> at java.lang.Object.wait(Object.**java:485)
>> at java.awt.EventQueue.**invokeAndWait(EventQueue.java:**1117)
>> - locked <7eae23890> (a java.awt.EventQueue$**1AWTInvocationLock)
>> at java.awt.Window.doDispose(**Window.java:1036)
>> at java.awt.Window.dispose(**Window.java:974)
>> at apple.awt.CTrayIconPeer.**disposeImpl(CTrayIconPeer.**java:58)
>> at apple.awt.PeerImpl.dispose(**PeerImpl.java:30)
>> at java.awt.TrayIcon.**removeNotify(TrayIcon.java:**701)
>> at java.awt.SystemTray.remove(**SystemTray.java:273)
>> - locked <7ed5e5968> (a java.awt.SystemTray)
>> at
>> com.elsten.bliss.ui.**systemtray.SystemTray$$**anonfun$shutdown$1.apply(*
>> *SystemTray.scala:149)
>> at
>> com.elsten.bliss.ui.**systemtray.SystemTray$$**anonfun$shutdown$1.apply(*
>> *SystemTray.scala:149)
>> at
>> scala.collection.**IndexedSeqOptimized$class.**
>> foreach(IndexedSeqOptimized.**scala:34)
>> at scala.collection.mutable.**ArrayOps.foreach(ArrayOps.**scala:38)
>> at com.elsten.bliss.ui.**systemtray.SystemTray.**
>> shutdown(SystemTray.scala:149)
>> at sun.reflect.**NativeMethodAccessorImpl.**invoke0(Native Method)
>> at
>> sun.reflect.**NativeMethodAccessorImpl.**invoke(**
>> NativeMethodAccessorImpl.java:**39)
>> at
>> sun.reflect.**DelegatingMethodAccessorImpl.**invoke(**
>> DelegatingMethodAccessorImpl.**java:25)
>> at java.lang.reflect.Method.**invoke(Method.java:597)
>> [...]
>>
>> "AWT-EventQueue-0" prio=6 tid=105d82800 nid=0x11505f000 in Object.wait()
>> [11505d000]
>>     java.lang.Thread.State: WAITING (on object monitor)
>> at java.lang.Object.wait(Native Method)
>> - waiting on <7ece2ed20> (a org.apache.felix.main.Main$1)
>> at java.lang.Thread.join(Thread.**java:1210)
>> - locked <7ece2ed20> (a org.apache.felix.main.Main$1)
>> at java.lang.Thread.join(Thread.**java:1263)
>> at
>> java.lang.**ApplicationShutdownHooks.**runHooks(**
>> ApplicationShutdownHooks.java:**79)
>> at
>> java.lang.**ApplicationShutdownHooks$1.**run(ApplicationShutdownHooks.**
>> java:24)
>> at java.lang.Shutdown.runHooks(**Shutdown.java:79)
>> at java.lang.Shutdown.sequence(**Shutdown.java:123)
>> at java.lang.Shutdown.exit(**Shutdown.java:168)
>> - locked <7faf9e240> (a java.lang.Class for java.lang.Shutdown)
>> at java.lang.Runtime.exit(**Runtime.java:90)
>> at java.lang.System.exit(System.**java:921)
>> at com.apple.eawt._**AppEventHandler.performQuit(_**
>> AppEventHandler.java:124)
>> - locked <7ed6a2420> (a com.apple.eawt._**AppEventHandler)
>> at com.apple.eawt.QuitResponse.**performQuit(QuitResponse.java:**31)
>> at
>> com.apple.eawt._**AppEventHandler$_**QuitDispatcher.**
>> performDefaultAction(_**AppEventHandler.java:382)
>> at
>> com.apple.eawt._**AppEventHandler$_**AppEventDispatcher$1.run(_**
>> AppEventHandler.java:487)
>> at java.awt.event.**InvocationEvent.dispatch(**InvocationEvent.java:209)
>> [...]
>>
>> Is there something I'm doing incorrectly? It looks like
>> "_AppEventHandler.performQuit" is calling System.exit... but won't this
>> be prone to deadlocks with OSGi?
>>
>> It's possible in this case that I chose to shutdown my app and this is
>> what sent the event. If this is the case how can I work around this? I'm
>> guessing that the removal of SystemTray items can't be done in this
>> case, or has to be done in some managed thread context.
>>
>> Just wondering if anyone else has seen this.
>>
>> Dan
>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
> --
> Ferry Huberts
>

Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Ferry Huberts <ma...@hupie.com>.

On 05/03/13 14:15, Dan Gravell wrote:
> In my OSGi app (running on Felix 4.0.2) I use the Java SystemTray to add
> items to the system tray. One of these items is a 'quit' item:
>
> miQuit.addActionListener(new ActionListener() {
> @Override
> def actionPerformed(e:ActionEvent) {
> platform.shutdown();
> }
> });
>
> Then, PlatformImpl.shutdown does a:


Why do you delegate to 'platform'.
I think you can call bundleContext.getBundle(0).stop() right there.

See if that fixes your deadlock
Otherwise try removing the systray items before calling stop.

>
> lastContext.getBundle(0).stop();
>
> Where lastContext is the BundleContext for the containing bundle. The
> SystemTray code and PlatformImpl are in different bundles. Stopping the
> bundles has the effect of calling:
>
> @Deactivate def shutdown() {
> awt.SystemTray.getSystemTray.getTrayIcons.foreach(systemTray.remove);
> }
>
> This is back on the SystemTray component (I'm using bnd style DS here).
>
> I am seeing a deadlock occur, but fairly infrequently and only on OS X.
> I managed to get a stack trace last time. Here are two suspicious
> looking threads (I attached the entire thing):
>
> "FelixStartLevel" daemon prio=5 tid=109c2d800 nid=0x10f371000 in
> Object.wait() [10f36e000]
>     java.lang.Thread.State: WAITING (on object monitor)
> at java.lang.Object.wait(Native Method)
> - waiting on <7eae23890> (a java.awt.EventQueue$1AWTInvocationLock)
> at java.lang.Object.wait(Object.java:485)
> at java.awt.EventQueue.invokeAndWait(EventQueue.java:1117)
> - locked <7eae23890> (a java.awt.EventQueue$1AWTInvocationLock)
> at java.awt.Window.doDispose(Window.java:1036)
> at java.awt.Window.dispose(Window.java:974)
> at apple.awt.CTrayIconPeer.disposeImpl(CTrayIconPeer.java:58)
> at apple.awt.PeerImpl.dispose(PeerImpl.java:30)
> at java.awt.TrayIcon.removeNotify(TrayIcon.java:701)
> at java.awt.SystemTray.remove(SystemTray.java:273)
> - locked <7ed5e5968> (a java.awt.SystemTray)
> at
> com.elsten.bliss.ui.systemtray.SystemTray$$anonfun$shutdown$1.apply(SystemTray.scala:149)
> at
> com.elsten.bliss.ui.systemtray.SystemTray$$anonfun$shutdown$1.apply(SystemTray.scala:149)
> at
> scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
> at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)
> at com.elsten.bliss.ui.systemtray.SystemTray.shutdown(SystemTray.scala:149)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> [...]
>
> "AWT-EventQueue-0" prio=6 tid=105d82800 nid=0x11505f000 in Object.wait()
> [11505d000]
>     java.lang.Thread.State: WAITING (on object monitor)
> at java.lang.Object.wait(Native Method)
> - waiting on <7ece2ed20> (a org.apache.felix.main.Main$1)
> at java.lang.Thread.join(Thread.java:1210)
> - locked <7ece2ed20> (a org.apache.felix.main.Main$1)
> at java.lang.Thread.join(Thread.java:1263)
> at
> java.lang.ApplicationShutdownHooks.runHooks(ApplicationShutdownHooks.java:79)
> at
> java.lang.ApplicationShutdownHooks$1.run(ApplicationShutdownHooks.java:24)
> at java.lang.Shutdown.runHooks(Shutdown.java:79)
> at java.lang.Shutdown.sequence(Shutdown.java:123)
> at java.lang.Shutdown.exit(Shutdown.java:168)
> - locked <7faf9e240> (a java.lang.Class for java.lang.Shutdown)
> at java.lang.Runtime.exit(Runtime.java:90)
> at java.lang.System.exit(System.java:921)
> at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:124)
> - locked <7ed6a2420> (a com.apple.eawt._AppEventHandler)
> at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:31)
> at
> com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:382)
> at
> com.apple.eawt._AppEventHandler$_AppEventDispatcher$1.run(_AppEventHandler.java:487)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
> [...]
>
> Is there something I'm doing incorrectly? It looks like
> "_AppEventHandler.performQuit" is calling System.exit... but won't this
> be prone to deadlocks with OSGi?
>
> It's possible in this case that I chose to shutdown my app and this is
> what sent the event. If this is the case how can I work around this? I'm
> guessing that the removal of SystemTray items can't be done in this
> case, or has to be done in some managed thread context.
>
> Just wondering if anyone else has seen this.
>
> Dan
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

-- 
Ferry Huberts

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Shutdown deadlock on OS X while doing AWT stuff

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Mar 5, 2013 at 2:15 PM, Dan Gravell
<el...@googlemail.com> wrote:
> ...Stopping the
> bundles has the effect of calling:
>
> @Deactivate def shutdown() {
> awt.SystemTray.getSystemTray.getTrayIcons.foreach(systemTray.remove);
> ...

It's been a long time since I did any AWT...shouldn't that be called
with EventQueue.invokeAndWait(...) to avoid trouble with the AWT
events queue thread?

-Bertrand

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org