Debugging a Production Memory Leak in Node.js
By Roee Bar1 min read
The Symptom
Our API server memory usage climbed steadily over 48 hours until it hit the container limit and got OOM-killed. Restarting fixed it temporarily, but the leak always came back.
Finding the Leak
- Took heap snapshots at 1-hour intervals using
--inspect - Compared retained object counts between snapshots
- Found an event listener that was never removed on every request
The fix was small once identified: a single removeListener call in the cleanup path. Sometimes the smallest bugs cause the biggest headaches.