0

I am implementing Spring Session with Redis.

I am getting the following exception:

SEVERE [RMI TCP Connection(3)-127.0.0.1]
org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks 
The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] 
(value [java.lang.ThreadLocal@e9d8bb]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] 
(value [io.netty.util.internal.InternalThreadLocalMap@1559b23]) 
but failed to remove it when the web application was stopped. Threads are going to be 
renewed over time to try and avoid a probable memory leak.

I have the following dependencies:

    <dependency>
        <groupId>io.lettuce</groupId>
        <artifactId>lettuce-core</artifactId>
        <version>5.2.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session-data-redis</artifactId>
        <version>2.2.1.RELEASE</version>
    </dependency>

I can see that lettuce-core is dragging in the io.netty classes:

[INFO] +- io.lettuce:lettuce-core:jar:5.2.1.RELEASE:compile
[INFO] |  +- io.netty:netty-common:jar:4.1.43.Final:compile
[INFO] |  +- io.netty:netty-handler:jar:4.1.43.Final:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.1.43.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.1.43.Final:compile
[INFO] |  +- io.netty:netty-transport:jar:4.1.43.Final:compile
[INFO] |  |  \- io.netty:netty-resolver:jar:4.1.43.Final:compile
[INFO] |  \- io.projectreactor:reactor-core:jar:3.3.0.RELEASE:compile
[INFO] |     \- org.reactivestreams:reactive-streams:jar:1.0.3:compile

The io.netty exception is a known, unfixed defect.

Is there a way to work around this? I've already tried the following:

  • Used version 5.1.8.RELEASE of lettuce-core: Same exception
  • Used version 5.0.5.RELEASE of lettuce-core: Get NoSuchMethodError: io.lettuce.core.api.StatefulConnection.closeAsync()

Is there a workaround for this problem?

Paul Reiners
  • 8,576
  • 33
  • 117
  • 202

1 Answers1

0

The bug report comments indicate this will mitigate the problem, but will not fully solve it. Perhaps an approach like the following will be good enough for your use case?

public class MyServletContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {

    }

    public void contextDestroyed(ServletContextEvent event) {
        io.netty.util.internal.InternalThreadLocalMap.destroy();
    }

}
Laird Nelson
  • 15,321
  • 19
  • 73
  • 127