Commit Graph

12 Commits

Author SHA1 Message Date
YonkoSam 1e6f65cf5e fix Memory leak in makeMutex - Promise never gets garbage collected (#2151)
* Memory leak in makeMutex - Promise never gets garbage collected

Hey, I've been debugging a memory leak in my application and traced it back to the makeMutex implementation.

The current implementation chains promises indefinitely without ever breaking the chain:

Every call to mutex() creates a new Promise that awaits the previous task, then becomes the new task. The problem is the old promises never get released because each one holds a reference to the previous through the closure.

What I found
Took a heap snapshot after running for a while and found hundreds of Promises from make-mutex.js holding ~15MB and growing. The retainer graph shows a long chain of Promises all pointing back to each other.

Since processingMutex handles every incoming message/notification, this chain grows constantly and never shrinks.

This keeps the same mutex behavior but lets the GC clean up old promises every 50 tasks instead of holding them forever.

* Refactor makeMutex to use AsyncMutex directly

* lint

* revert
2025-12-12 04:35:24 +02:00
canove fa706d0b50 chore: format everything 2025-05-06 12:10:19 -03:00
Rajeh Taher 18ac07df8e lint: 0 warnings left 2024-10-14 05:15:10 +03:00
Alan Mosko 0d53fbe7fa Update make-mutex.ts 2023-01-17 11:49:49 -03:00
Alan Mosko 05dd53e2ce wip 2023-01-17 11:29:10 -03:00
Alan Mosko c398aa3ca4 Merge branch 'master' into poll 2023-01-16 11:46:20 -03:00
Adhiraj Singh 5efb0ebbea chore: remove mutex-start log 2023-01-13 10:20:28 +05:30
Alan Mosko 78f04d8714 wip 2023-01-11 23:58:29 -03:00
Adhiraj Singh bcf33d786c chore: log mutex deadlocks 2022-11-25 22:00:25 +05:30
Adhiraj Singh 1f2a6641f3 feat: mutex processing in a chat to preserve order of events 2022-01-22 14:07:06 +05:30
Adhiraj Singh 8f11f0be76 chore: add linting 2022-01-19 15:54:02 +05:30
Adhiraj Singh bb5f13d188 fix: mutex app state sync to prevent race conditions that log connection out 2021-11-18 11:30:35 +05:30