Skip to content

[Bug] Thread-locals are not being cleaned up when Serviets throw exceptions #2081

@lprimak

Description

@lprimak

Search before asking

  • I had searched in the issues and found no similar issues.

Environment

When undeploying application from app server, it complains about Thread Locals related to Shiro.
This only happens when Servlets start additional threads.

Shiro version

1.1.0-2.0.3

What was the actual outcome?

ThreadLocals are left behind

What was the expected outcome?

ThreadLocals are cleaned up

How to reproduce

TBD

Debug logs

[#|2025-04-12T15:35:57.088-0500|INFO|Payara 6.2025.3|jakarta.enterprise.web|_ThreadID=136;_ThreadName=admin-thread-pool::admin-listener(1);_TimeMillis=1744490157088;_LevelValue=800;|
  WebModule[/logbook] ServletContext.log():Cleaning up Shiro Environment|#]

[#|2025-04-12T15:35:57.101-0500|SEVERE|Payara 6.2025.3|jakarta.enterprise.web.util|_ThreadID=136;_ThreadName=admin-thread-pool::admin-listener(1);_TimeMillis=1744490157101;_LevelValue=1000;|
  The web application [/logbook] created a ThreadLocal with key of type [org.apache.shiro.util.ThreadContext.InheritableThreadLocalMap] (value [org.apache.shiro.util.ThreadContext$InheritableThreadLocalMap@18060eba]) and a value of type [java.util.HashMap] (value [{org.apache.shiro.util.ThreadContext_SECURITY_MANAGER_KEY=org.apache.shiro.ee.filters.ShiroFilter$WrappedSecurityManager@13a4bf17, org.apache.shiro.util.ThreadContext_SUBJECT_KEY=DelegatingSubject{principals=null, authenticated=false, host='******, session='******', sessionCreationEnabled=true, securityManager=org.apache.shiro.ee.filters.ShiroFilter$WrappedSecurityManager@13a4bf17}}]) 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.|#]

[#|2025-04-12T15:35:57.101-0500|SEVERE|Payara 6.2025.3|jakarta.enterprise.web.util|_ThreadID=136;_ThreadName=admin-thread-pool::admin-listener(1);_TimeMillis=1744490157101;_LevelValue=1000;|
  The web application [/logbook] created a ThreadLocal with key of type [org.apache.shiro.util.ThreadContext.InheritableThreadLocalMap] (value [org.apache.shiro.util.ThreadContext$InheritableThreadLocalMap@18060eba]) and a value of type [java.util.HashMap] (value [{org.apache.shiro.util.ThreadContext_SECURITY_MANAGER_KEY=org.apache.shiro.ee.filters.ShiroFilter$WrappedSecurityManager@13a4bf17, org.apache.shiro.util.ThreadContext_SUBJECT_KEY=DelegatingSubject{principals=null, authenticated=false, host='******, session='******', sessionCreationEnabled=true, securityManager=org.apache.shiro.ee.filters.ShiroFilter$WrappedSecurityManager@13a4bf17}}]) 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.|#]

[#|2025-04-12T15:35:57.101-0500|SEVERE|Payara 6.2025.3|jakarta.enterprise.web.util|_ThreadID=136;_ThreadName=admin-thread-pool::admin-listener(1);_TimeMillis=1744490157101;_LevelValue=1000;|
  The web application [/logbook] created a ThreadLocal with key of type [org.apache.shiro.util.ThreadContext.InheritableThreadLocalMap] (value [org.apache.shiro.util.ThreadContext$InheritableThreadLocalMap@18060eba]) and a value of type [java.util.HashMap] (value [{org.apache.shiro.util.ThreadContext_SECURITY_MANAGER_KEY=org.apache.shiro.ee.filters.ShiroFilter$WrappedSecurityManager@13a4bf17, org.apache.shiro.util.ThreadContext_SUBJECT_KEY=DelegatingSubject{principals=null, authenticated=false, host='******, session='******', sessionCreationEnabled=true, securityManager=org.apache.shiro.ee.filters.ShiroFilter$WrappedSecurityManager@13a4bf17}}]) 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.|#]

Metadata

Metadata

Assignees

Labels

CLAcoreCore ModulesjavaPull requests that update Java code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions