corretto / corretto-11

Amazon Corretto 11 is a no-cost, multi-platform, production-ready distribution of OpenJDK 11
GNU General Public License v2.0
672 stars 106 forks source link

System.exit(0) not able to terminate the process when application running with Oracle UCP shutdownhook #373

Open syedjinnah opened 1 month ago

syedjinnah commented 1 month ago

Describe the bug

In our Java application, when we are trying to kill Java Process programmatically using System.exit(0), the process is not getting killed for long time even after 5 minutes or 10 minutes. When we took thread dump of that Java process, after 5 minutes we could see, Java process not getting killed as thread is waiting in Shutdown hook where we see await call with timeout period as 10 seconds but still the thread is not coming out of await method and its running indefinitely.

We had this issue always when we run with Amazon Corretto 11.0.17 later we upgraded to 11.0.24.8.1

To Reproduce

Have java application, use Oracle UCP for connection pooling. issue shutdown by calling System.exit(0)

This issue is random behavior.

Expected behavior

When we issue shutdown using System.exit(0) the process and its PID should be clean exit but not happening.

Screenshots

Two threads during the thread dump taken after 115 seconds (appx 2 min) "Thread-2" #17 prio=5 os_prio=0 cpu=1.64ms elapsed=115.74s tid=0x00007f8836a4e800 nid=0x1be022 waiting on condition [0x00007f879110c000] java.lang.Thread.State: TIMED_WAITING (parking) at jdk.internal.misc.Unsafe.park(java.base@11.0.24/Native Method)

"main" #1 prio=5 os_prio=0 cpu=20511.55ms elapsed=185707.18s tid=0x00007f883402c000 nid=0x15b49e in Object.wait() [0x00007f883e017000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(java.base@11.0.24/Native Method)

Platform information

OS: RHEL 8.8
Java Version: 11.0.24+8-LTS mixed mode
syedjinnah commented 1 month ago

coreA.txt Attaching thread dump for reference

WithEnoughCoffee commented 1 month ago

Thanks looking into it