Skip to content

Undeploy shows SecurityContextImpl [Null authentication] memory leak on tomcat #9841

@shirosaki

Description

@shirosaki

Describe the bug
Create a spring boot war application and deploy to tomcat server.
Undeploy the app from tomcat causes the following log.

SEVERE [Catalina-utility-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [xxxxxx] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@b58535e3]) and a value of type [org.springframework.security.core.context.SecurityContextImpl] (value [SecurityContextImpl [Null authentication]]) 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.

To Reproduce
Put war file to webapps directory in tomcat and remove the war from webapps.
Spring boot v2.4.1, Java 11 and tomcat 9.0.41.

Expected behavior
SecurityContextImpl [Null authentication] is not created with ThreadLocal or removed on stopping.

If SecurityContextHolder strategy is MODE_GLOBAL, this doesn't occur.
I don't find how to remove SecurityContextImpl [Null authentication].

Metadata

Metadata

Assignees

Labels

in: webAn issue in web modules (web, webmvc)type: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions