From 5b467a5307832de05c340d2c48f2520ab867c27b Mon Sep 17 00:00:00 2001 From: Adrian Jost <22987140+adrianjost@users.noreply.github.com> Date: Fri, 7 Jul 2023 11:15:59 +0200 Subject: [PATCH] Fix Memory Leak in AsyncHttpCall affecting auth.listUsers fixes 2235 The socket code was only introduced to fix a bug in NodeJS 12 (https://github.com/firebase/firebase-admin-node/commit/db8be2620a5c9cfc5b9824d9d2487ab9815f5baf) and since then has even needed a patch (https://github.com/firebase/firebase-admin-node/commit/1a34bc49373a5a34bb0efc006ea156d66168103c). However the code does not seem necessary at all anymore. Removing this code resolved the described memory leak. --- src/utils/api-request.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/utils/api-request.ts b/src/utils/api-request.ts index 64fc49d87c..485ce3c8eb 100644 --- a/src/utils/api-request.ts +++ b/src/utils/api-request.ts @@ -504,14 +504,6 @@ class AsyncHttpCall { if (timeout) { // Listen to timeouts and throw an error. req.setTimeout(timeout, timeoutCallback); - req.on('socket', (socket) => { - socket.setMaxListeners(socket.getMaxListeners() + 1); - socket.setTimeout(timeout, timeoutCallback); - socket.on('end', () => { - socket.setTimeout(0); - socket.setMaxListeners(Math.max(socket.getMaxListeners() - 1, 0)); - }); - }); } // Send the request