首页 > 解决方案 > 使用 Redis 实现 Spring Session 时出现“io.netty”异常

问题描述

我正在用 Redis 实现 Spring Session。

我收到以下异常:

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.

我有以下依赖项:

    <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>

我可以看到它lettuce-core正在拖入io.netty类:

[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

io.netty例外是一个已知的、未修复的缺陷

有没有办法解决这个问题?我已经尝试过以下方法:

有解决此问题的方法吗?

标签: redisnettyspring-session

解决方案


错误报告评论表明这将缓解问题,但不会完全解决它。也许像以下这样的方法对您的用例来说已经足够了?

public class MyServletContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {

    }

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

}

推荐阅读