-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak in getAuth(...).listUsers(...) #2235
Comments
We have narrowed down the issue to https://github.com/firebase/firebase-admin-node/blob/master/src/utils/api-request.ts#L507-514 We figured out, that in newer node versions, |
BTW here is an even simpler example with the memory leak: const { initializeApp } = require("firebase-admin/app");
const { getAuth } = require("firebase-admin/auth");
const app = initializeApp({
projectId: "TODO",
});
const waitSeconds = (seconds) =>
new Promise((resolve) => setTimeout(resolve, seconds * 1000));
async function main() {
while (true) {
await getAuth(app).listUsers(1000);
waitSeconds(2);
}
}
main(); |
Hi @adrianjost Thank you for the highly detailed issue report! The fix you proposed in #2236 looks good to me. We can merge the fix once we complete the review. Thanks! |
Environment
Problem
Steps to reproduce:
We discovered a Memory Leak when running the list_all_users example code from https://firebase.google.com/docs/auth/admin/manage-users#list_all_users.
The data loaded from
getAuth(app).listUsers(1000, nextPageToken)
is not garbage collected and causes the memory footprint of our authentication backup to grow and eventually run out of memory.Every blue bar is memory that is still used with is ~1MB/1000 Users making it almost impossible to use this function to backup multiple GB of user data.
The problematic path seems to be within:
node_modules/firebase-admin/lib/utils/api-request.js
.Side-note: We only started noticing this issue with node v20, with node v18 and below we did not have the issue when using our production bundle that is generated with typescript and webpack. We could go back to previous versions and can see that the memory is correctly cleaned up in older node versions. Unfortunately we couldn't figure out what exactly the difference to the simple issue demo script I've added below is, which has the issue even on older versions.
It just shows us, that there is now an issue that didn't exist before.
We could also see the same when not using a loop and just calling
auth.listUsers(1000)
once, so the issue is not in the boilerplate around. Also the issue goes away when we mock this function call.Here you can see a Memory Profile of the issue with our webpack output. You can clearly see, that in node20 the blue bars that are kept are way larger. In node18 and before the data was immediately cleaned up.
Relevant Code:
The text was updated successfully, but these errors were encountered: