Failed to stop password4j-worker thread

#163 · closed · 4 comments

View on GitHub ↗

fangornoftheforest

**Describe the bug** When deploying a web application using Password4j Tomcat 11 with Java 21, a warning is thrown indicating that the thread password4j-worker-X was not properly stopped when the application shuts down. Possible memory leak. **To Reproduce** Always happens when shutting down, forces an extra shutdown command. **Environment:** - OS: Windows/Linux - JDK: 21 - Version: 1.8.3 **Additional context** `05-May-2025 16:36:56.113 WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [foo] appears to have started a thread named [password4j-worker-20] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.base/jdk.internal.misc.Unsafe.park(Native Method) java.base/java.util.concurrent.locks.LockSupport.park(LockSupport.java:371) java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionNode.block(AbstractQueuedSynchronizer.java:519) java.base/java.util.concurrent.ForkJoinPool.unmanagedBlock(ForkJoinPool.java:3780) java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3725) java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1707) java.base/java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:435) java.base/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1070) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) java.base/java.lang.Thread.run(Thread.java:1583)` **Working example** https://github.com/fangornoftheforest/Password4jThreadIssue/tree/master Unfortunately https://github.com/Password4j/password4j/issues/162 did not fix the issue, the problem persists. I've updated the example to use 1.8.3

Comments

firaja

Ciao @fangornoftheforest, while working on #162 I used the example you kindly shared with me. How do you start tomcat? Maybe you run it in a different way I do (`catalina.sh run`) Secondly, the example still contains version 1.8.2, maybe it's a typo ty

fangornoftheforest

Hi Firaja, version in pom.xml has been updated (change wasn't committed). Might be OS difference, I use catalina.bat run. Will test AlmaLinux tomorrow. Thanks in advance!

fangornoftheforest

Issue present on Linux, throws these errors: "password4j-worker-17" #162 [264] prio=5 os_prio=0 cpu=51.46ms elapsed=7.45s tid=0x00007fe654effc70 nid=264 waiting on condition [0x00007fe54dad9000] java.lang.Thread.State: WAITING (parking) at jdk.internal.misc.Unsafe.park([email protected]/Native Method) - parking to wait for <0x0000000083e80098> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park([email protected]/LockSupport.java:371) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionNode.block([email protected]/AbstractQueuedSynchronizer.java:519) at java.util.concurrent.ForkJoinPool.unmanagedBlock([email protected]/ForkJoinPool.java:3780) at java.util.concurrent.ForkJoinPool.managedBlock([email protected]/ForkJoinPool.java:3725) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await([email protected]/AbstractQueuedSynchronizer.java:1707) at java.util.concurrent.LinkedBlockingQueue.take([email protected]/LinkedBlockingQueue.java:435) at java.util.concurrent.ThreadPoolExecutor.getTask([email protected]/ThreadPoolExecutor.java:1070) at java.util.concurrent.ThreadPoolExecutor.runWorker([email protected]/ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run([email protected]/ThreadPoolExecutor.java:642) at java.lang.Thread.runWith([email protected]/Thread.java:1596) at java.lang.Thread.run([email protected]/Thread.java:1583)

firaja

Hi @fangornoftheforest, sorry for the delay but I'm very busy these days. Thank you for you further analysis. There is a PR recently opened that could solve the prolem #165 Can you test it and see if it fixes the problem? ty