Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the async and race conditions pattern
A missing await, unbuffered channel deadlocks, ConcurrentModificationException, and data races under load.
What went wrong: Returning early on error (amount < 0) bypassed the mu.Unlock() call at the end of the function, permanently locking the mutex and causing all future acquisitions to deadlock.
The fix: Use defer mu.Unlock() immediately following mu.Lock() so the mutex is guaranteed to unlock on every exit path.
Remember: Always pair sync.Mutex.Lock() with defer mu.Unlock() to guarantee release across all return paths.
The pattern behind it: async and race conditions.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/4ecee4d7-0133-4610-ae5b-a07857ecb10f" title="Debugging challenge: Missing mutex unlock on early error return" 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/4ecee4d7-0133-4610-ae5b-a07857ecb10f">TryBugHunt</a></p>