Strange problem
I'm trying to shutdown my Java app properly on receiving signal, either send manually via kill. I tried kill SIGTERM, SIGHUP, SIGINT etc. and every time JVM just stops without calling Runtime shutdown hooks, finally block or signal traps created in Java code.
Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook") {
@Override
public void run() {
vd.pretendRemoveAll();
}
});
And added handlers when shutdownHook did not work
SignalHandler h = new SignalHandler() {
@Override
public synchronized void handle(Signal sig) {
_logger.warn("Received signal: {}", sig);
vd.pretendRemoveAll();
System.exit(0);
}
};
Signal.handle(new Signal("INT"), h);
Signal.handle(new Signal("KILL"), h);
Signal.handle(new Signal("HUP"), h);
Signal.handle(new Signal("TERM"), h);
I'm running on Ubuntu 12.04 with Java java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
I tried also with Oracle Java jdk1.6.0_37, the same effect
When I use strace on the process to see what happens I get:
user@server:~/appdir$ sudo strace -v -p 32277Process 32277 attached - interrupt to quitfutex(0x7f667f07d9d0, FUTEX_WAIT, 32278, NULL) = ? ERESTARTSYS (To be restarted) --- SIGTERM (Terminated) @ 0 (0) --- futex(0x7f667e2543e0, FUTEX_WAKE_PRIVATE, 1) = 1 rt_sigreturn(0x7f667e2543e0) = 202 futex(0x7f667f07d9d0, FUTEX_WAIT, 32278, NULLPANIC: attached pid 32277 exited with 143
And this NULLPANIC looks suspicious, but I have no idea what next.
I tested that code on Mac and works no problem. Any ideas what's causing the problem and how to fix that? Is it some security feature/policy that needs to be set?