Skip to content

[Bug] [API] LoginHandlerInterceptor has a possibility of memory leak #17469

@njnu-seafish

Description

@njnu-seafish

Search before asking

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

What happened

1, the preHandle method trigger the following logic:
ThreadLocalContext.getTimezoneThreadLocal().set(user.getTimeZone());
2,then the postHandle method trigger the following logic:
ThreadLocalContext.getTimezoneThreadLocal().remove();
3, However, if the Controller method throws an exception, the postHandle method will not be called. If this situation occurs frequently, a memory leak problem will occur.

What you expected to happen

Perform resource cleanup operations in the afterCompletion method, because the afterCompletion method is executed after the entire request processing is complete, regardless of whether the request was handled successfully (i.e., whether an exception was thrown or not).

How to reproduce

1, Controller throws an exception
2, Frequently logging in and accessing the controller
3, postHandle is only called after the Controller is successfully executed. If the Controller throws an exception, postHandle will not be executed, resulting in the ThreadLocal not being cleaned up, which may lead to memory leaks or dirty data.

Anything else

No response

Version

dev

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions