Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the scope and closure bugs pattern
Every callback reports the last value, a counter never increments, UnboundLocalError on a variable you can see.
What went wrong: Web servers and thread pools reuse threads for multiple incoming requests. If a task fails to call ThreadLocal.remove(), its value leaks into whatever unrelated task next runs on that pooled thread.
The fix: Always wrap ThreadLocal operations in a try-finally block and call context.remove() in the finally block.
Remember: Always pair ThreadLocal.set() with ThreadLocal.remove() in a finally block to prevent thread pool data leakage.
The pattern behind it: scope and closure bugs.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/0752a49b-9b3e-43a5-a9dc-519f1912f55b" title="Debugging challenge: ThreadLocal memory leak in thread pool environment" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/0752a49b-9b3e-43a5-a9dc-519f1912f55b">TryBugHunt</a></p>