Skip to content

Fix memory leak in CacheManager by reusing InheritableThreadLocal ins…#6731

Open
rajat315315 wants to merge 1 commit into
apache:masterfrom
rajat315315:fix/cachemanager-threadlocal-leak
Open

Fix memory leak in CacheManager by reusing InheritableThreadLocal ins…#6731
rajat315315 wants to merge 1 commit into
apache:masterfrom
rajat315315:fix/cachemanager-threadlocal-leak

Conversation

@rajat315315

@rajat315315 rajat315315 commented Jul 21, 2026

Copy link
Copy Markdown

Closes: #6730

Description

We have resolved the progressive memory leak in CacheManager by reusing a single InheritableThreadLocal instance and clearing per-thread state via .remove(). All changes have been tested, benchmarked under concurrent load, and committed on a dedicated branch.


Motivation and Context

How Has This Been Tested?

Automated Unit Tests

./gradlew :src:protocol:http:test --tests "org.apache.jmeter.protocol.http.control.TestCacheManager*"

Output:

TestCacheManagerThreadIteration > testClearCacheReusesThreadLocalInstance() PASSED
TestCacheManagerHC4 > testClearEachIteration() PASSED
TestCacheManagerHC4 > testClear() PASSED
... (23 tests total)
BUILD SUCCESSFUL in 51s

Concurrent Benchmark Verification

./gradlew :src:protocol:http:test --tests "org.apache.jmeter.protocol.http.control.TestCacheManagerMemoryLeak"

Output:

TestCacheManagerMemoryLeak > testBenchmarkThreadLocalReuseUnderConcurrentLoad() PASSED
BUILD SUCCESSFUL in 6s
  • 0 orphaned InheritableThreadLocal objects left in worker threads.
  • Memory leak eliminated.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory Leak in CacheManager: InheritableThreadLocal Recreated Without Cleanup on Every Iteration

1 participant