<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.4.1</li>
<li>Operating System version: Linux  4.15.0-122-generic <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="70300267" data-permission-text="Title is private" data-url="https://github.com/apache/dubbo/issues/124" data-hovercard-type="issue" data-hovercard-url="/apache/dubbo/issues/124/hovercard" href="https://github.com/apache/dubbo/issues/124">#124</a>~16.04.1-Ubuntu SMP Thu Oct 15 16:08:36 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux</li>
<li>Java version: 1.8.0_201</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>Provide a method in service-side and return a large data( for example 4M).</li>
<li>Create a fixed threadpool(fox example,with 100 threads), and invoke the remote method in a loop.</li>
<li>After the loop finished, the memory about 400M was always kept by <code class="notranslate">InternalThreadLocalMap</code>.</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">After all finished, memory kept by <code class="notranslate">InternalThreadLocalMap</code>  will be revoked by GC.</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">The memory about 400M was always kept by <code class="notranslate">InternalThreadLocalMap</code>.</p>
<h3 dir="auto">More</h3>
<p dir="auto">The <a href="https://github.com/liusf1993/dubbo-test">demo</a> can reproduce this issue.<br>
Other information I can  provided:<br>
The leak memory was created by <code class="notranslate">FutureContext#futureTL</code>, and data in threadlocal can be traced by <code class="notranslate">InternalThreadLocal#VARIABLES_TO_REMOVE_INDEX</code>,  invoke method <code class="notranslate">InternalThreadLocal#removeAll</code> in consumer filter can free the memory, but I can't  find any usages of this method. Now I add <code class="notranslate">InternalThreadLocal#removeAll</code> in an extended  filter to solve this problem in my program.<br>
If this is configuration error, thanks for your correction.</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<p dir="auto">The test <code class="notranslate">dubbo-common,org.apache.dubbo.common.threadlocal.InternalThreadLocalTest.testSize</code> is not idempotent and fails if run twice in the same JVM, because it pollutes state shared among tests.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: dubbo-2.7.8</li>
<li>Operating System version: macOS 10.15.6</li>
<li>Java version: 1.8.0_151</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>Run unit test <code class="notranslate">InternalThreadLocalTest.testSize</code> twice in the same JVM.</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">Specifically, when running <code class="notranslate">InternalThreadLocalTest.testSize</code> twice in the same JVM, both runs should pass.(The test should not modify shared states among the tests)</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">While the first run of <code class="notranslate">InternalThreadLocalTest.testSize</code> passes, the second run of the test fails with the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: org.opentest4j.AssertionFailedError: size method is wrong! ==&gt;
Expected :1 Actual   :3
at org.apache.dubbo.common.threadlocal.InternalThreadLocalTest.testSize(InternalThreadLocalTest.java)"><pre class="notranslate"><code class="notranslate">error: org.opentest4j.AssertionFailedError: size method is wrong! ==&gt;
Expected :1 Actual   :3
at org.apache.dubbo.common.threadlocal.InternalThreadLocalTest.testSize(InternalThreadLocalTest.java)
</code></pre></div>