1

To be clear, this is a upstart/linux debugging problem not a java problem per-se.

I have a java application installing a shutdownhook. It shows some funny behaviour in ubuntu-GNOME, namely that the shutdown hook never run if a restart or power off were scheduled. At first i thought it was a problem with my shutdown hook, so i simplified it until it was only writing a line to file (yes i know about the log4j2 logger problem with shutdownhooks so i disabled theirs too). Then when that didn't work i started hacking /etc/init/sendsigs

I added this to the beginning of the do_stop function:

app="$(jps | grep appname.jar | cut -d' ' -f1)"
echo "$app" >>  "/home/i30817/output.txt"

sure enough, that showed that it was no longer running, so the shutdown hooks were never activated by sendsigs Then i used lastcomm from here replacing my edit of sendsigs by:

echo `/home/i30817/lastcomm` >  "/home/i30817/output.txt"

And it told me that the java process exited with 1 and was not signaled:

java X i30817 ?? 10.26 secs Sun Mar 2 12:44 E 1

but this still didn't help me find what actually killed it and why. This problem is not reproducible with a smaller example, so it's probably something in the larger application (but not the shutdown hook, since it was minimized) that doesn't like the shutdown process and manages to kill the process, but i can't figure it out... redirecting the process output to a file doesn't say anything either eg:

java -jar /home/i30817/Documents/projects/app/dist/app.jar > allout.text 2>&1 

is empty of everything but normal app output Can you help me figure out this? There are a lot of duplicate questions about the same thing too (but they think it's the shutdownhooks malfunctioning).

edit: more detail, now that i understand the problem a bit better. I think now that processes not being there on sendsigs is normal. Java applications, and maybe others use a protocol from the window manager where SIGHUP, SIGHUP and SIGCONT is sent on shutdown/logout. The JVM hooks SIGHUP to launch the shutdown hooks. I tested this with a very small example that only adds a shutdownhook and has a infinite cycle on main, and ran it with a system tap script in the background:

  java -jar app.jar 

and in another shell

  sudo stap -o process.txt sigkill.stp

However when i tried that with my application i think i found the culprit:

  PROCESS: SIGSEGV java.signal_generate sent to java 2280

but don't really know what to do about it considering there is no thread dump or anything and this is strange to reproduce (only my app, only during shutdown).

edit2: now i suspect the reason for the 'abrupt' termination without core dump is the ulimit during shutdown. So i'm trying to solve that in preparation for a bug report. I edited /etc/security/limits.conf to add this and rebooted

   *               soft    core            unlimited
   root            hard    core            unlimited
   *               hard    rss             10000

(fs.suid_dumpable=2 was set by ubuntu, no apparmor i think) but during shutdown i edited /etc/init.d/sendsigs again to print ulimit -a and sleep for 30 seconds before killing the processes, and it seems that during reboot the ulimit gets reset again? And moreover, it had a different output like it was using another executable version, for instance instead of saying 'core file size' it had 'core(dump)' or something like that).

edit3: ah, i need to have fs.suid_dumpable=1 instead - gonna try now. Maybe the init ulimit doesn't matter for shutdown core dump triggering. After all the jvm was executed from the user env so it should be using the user ulimit.

edit4: eh. After much commenting of code i reached the following conclusion that i could have reached from RTFM:

  1. the sigsegvs are harmless.

  2. the non-zero exit code is not.

If the AWT is still up, the signal is always non zero and the shutdown hooks never run. Even a small example still prevents execution of shutdown hooks in linux reboot if a JFrame is up (unlike windows, where they will start). Looking at the source, the application shutdownhooks are run on a slot by themselves, slot 1. I bet slot '0' is the AWT and that is halting the system somehow.

I guess it's time to check the package private signal handling libs to see if i can get SIGHUP before the JVM decides to terminate everything without even giving the opportunity for cleanup code to run.

Community
  • 1
  • 1
i30817
  • 1,356
  • 2
  • 13
  • 26
  • Do you have the source for the different applications? If I had this problem I would setup eclipse to debug the server side setting break points. I mention this because you found that the java process was not signaled. – D-Klotz Mar 02 '14 at 13:31
  • There are no different applicatios, this is all a client side swing application. I'm actually testing this by scheduling a reboot. I do have its source. – i30817 Mar 02 '14 at 13:32
  • @D-Klotz i posted a example here: http://stackoverflow.com/questions/22262190/is-this-a-jvm-or-gnome-3-bug – i30817 Mar 07 '14 at 23:00

1 Answers1

0

According to docs

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly.... If the virtual machine aborts then no guarantee can be made about whether or not any shutdown hooks will be run.

jcalloway
  • 1,155
  • 1
  • 15
  • 24