-
Bug
-
Resolution: Fixed
-
P2
-
7, 8, 9
-
b125
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8196272 | 8u191 | Abdul Kolarkunnu | P2 | Resolved | Fixed | b01 |
JDK-8201088 | 8u181 | Unassigned | P2 | Resolved | Fixed | b01 |
JDK-8191289 | 8u172 | Abdul Kolarkunnu | P2 | Closed | Fixed | b01 |
JDK-8203121 | emb-8u181 | Abdul Kolarkunnu | P2 | Resolved | Fixed | master |
This happens because ApplicationShutdownHooks.runHooks joins the shutdown hooks. This works normally if interrupt status is not set in advance. But if it does, we exit the loop early:
static void runHooks() {
Collection<Thread> threads;
synchronized(ApplicationShutdownHooks.class) {
threads = hooks.keySet();
hooks = null;
}
for (Thread hook : threads) {
hook.start();
}
for (Thread hook : threads) {
try {
hook.join();
} catch (InterruptedException x) { } // oops, no join for you, falling through...
}
}
...and already started shutdown hooks begin to race against the rest of the shutdown sequence. Notably, this may lead to premature VM shutdown, with shutdown hooks not fully executed, as test demonstrates.
ApplicationShutdownHooks is called from the thread that originally called System.exit:
j java.lang.ApplicationShutdownHooks.runHooks()V+113
j java.lang.ApplicationShutdownHooks$1.run()V+0
j java.lang.Shutdown.runHooks()V+100
j java.lang.Shutdown.sequence()V+26
j java.lang.Shutdown.exit(I)V+95
j java.lang.Runtime.exit(I)V+14
j java.lang.System.exit(I)V+4
j Main.main([Ljava/lang/String;)V+20
Full jtreg test:
http://cr.openjdk.java.net/~shade/8154017/ShutdownInterruptedMain.java
static void runHooks() {
Collection<Thread> threads;
synchronized(ApplicationShutdownHooks.class) {
threads = hooks.keySet();
hooks = null;
}
for (Thread hook : threads) {
hook.start();
}
for (Thread hook : threads) {
try {
hook.join();
} catch (InterruptedException x) { } // oops, no join for you, falling through...
}
}
...and already started shutdown hooks begin to race against the rest of the shutdown sequence. Notably, this may lead to premature VM shutdown, with shutdown hooks not fully executed, as test demonstrates.
ApplicationShutdownHooks is called from the thread that originally called System.exit:
j java.lang.ApplicationShutdownHooks.runHooks()V+113
j java.lang.ApplicationShutdownHooks$1.run()V+0
j java.lang.Shutdown.runHooks()V+100
j java.lang.Shutdown.sequence()V+26
j java.lang.Shutdown.exit(I)V+95
j java.lang.Runtime.exit(I)V+14
j java.lang.System.exit(I)V+4
j Main.main([Ljava/lang/String;)V+20
Full jtreg test:
http://cr.openjdk.java.net/~shade/8154017/ShutdownInterruptedMain.java
- backported by
-
JDK-8196272 Shutdown hooks are racing against shutdown sequence, if System.exit()-calling thread is interrupted
-
- Resolved
-
-
JDK-8201088 Shutdown hooks are racing against shutdown sequence, if System.exit()-calling thread is interrupted
-
- Resolved
-
-
JDK-8203121 Shutdown hooks are racing against shutdown sequence, if System.exit()-calling thread is interrupted
-
- Resolved
-
-
JDK-8191289 Shutdown hooks are racing against shutdown sequence, if System.exit()-calling thread is interrupted
-
- Closed
-