DoctorMcKay/node-steam-user

Memory leak around g_ProcessPersonaSemaphore

Sadzurami opened this issue · 2 comments

Describe the bug

Memory usage increases while the application is running.
The app crashes after a few hours.

Application logic: logOn -> gamesPlayed(440, true) -> createAuthSessionTicket(440) -> idle
With 500+ SteamUser instances.

Versions

4.28.5
18.5.0

Screenshots and Error Logs

C:\snapshot\yet-another-reward\node_modules\steam-user\components\friends.js:978
                        g_ProcessPersonaSemaphore.wait(async (release) => {
                                                       ^

RangeError: Maximum call stack size exceeded
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js v18.5.0

Or:

<--- Last few GCs --->

[5780:000001300C5465C0] 11460942 ms: Mark-sweep 2007.5 (2080.3) -> 1991.5 (2080.3) MB, 3335.5 / 0.5 ms  (average mu = 0.129, current mu = 0.030) allocation failure; scavenge might not succeed
[5780:000001300C5465C0] 11464521 ms: Mark-sweep 2007.5 (2080.3) -> 1991.5 (2080.3) MB, 3337.8 / 0.5 ms  (average mu = 0.099, current mu = 0.067) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

The problem exists even with one instance.
Try to start the instance normally, check the memory usage, then disable the handler here

SteamUserBase.prototype._handlerManager.add(EMsg.ClientPersonaState, function(body) {

A simple immediate return would be enough.
Start the instance and check the memory usage now.

Disabling the EMsg.ClientClanState handler helps with memory leaks and reduces memory usage by 75%.

Before 4.28.4 memory usage was ~50% lower.

Behavior similar to
#437

In both cases, semaphores are used.
Maybe the semaphore is not working properly?