Thanks, Bogdan. There is no misconfiguration on your part. The issue is two fold. Tomcat is extremely strict about checking ThreadLocal use. HikariCP has had to bend over backward to avoid these leak warnings (see issue
#39,
#148). Basically, in order to avoid these Tomcat warnings, a library cannot subclass ThreadLocal at all. For some libraries, this is a tall order. We also had to
bend over backward with the addition of WeakReferences.
A basic (but technical) summary of the issue is this. When Tomcat starts a WAR, all classes in that WAR are loaded by a dedicated ClassLoader. In Java, classes are only garbage collected when the ClassLoader that loaded them is itself garbage collected. When Tomcat un-deploys a WAR, it throws away the dedicated ClassLoader. However...
Because threads are shared across WARs, if a class in the WAR puts associates a ThreadLocal subclass that is itself contained in the WAR ... or if a class even puts a class local to the WAR into a regular ThreadLocal ... then when the WAR is un-deployed, the ThreadLocals (which are tied to threads whose lifetime extend beyond the WAR) retain references to classes loaded by the dedicated ClassLoader. This prevents the ClassLoader itself, and all of the classes that it loaded from being garbage collected.
ThreadLocals are completely isolated from other threads, and there is no way for Tomcat or even the library itself to clean them up.
I understand Tomcat's motivation for the warning. And it did use to be a WARN. Now it is classified as SEVERE. I think this is a little bit disingenuous. As noted in the message, " Threads are going to be renewed over time to try and avoid a probable memory leak." This will prevent any leak. So, in reality, whether a WAR leaks or not is ultimately in Tomcat's hands. If they detect these thread locals, they could simply more aggressively schedule the retirement of existing threads and the creation of new ones.
TLDR; Tomcat is "correct", but the warning is ultimately BS and mostly scares users.
The "issue" ultimately lies with netty, but there is about a 0.5% chance of them changing what they are doing.