Skip to content
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

fs.promises.rm recursive on a huge directory-tree with missing permissions can result in OOM #56433

Open
viyaha opened this issue Jan 2, 2025 · 1 comment

Comments

@viyaha
Copy link

viyaha commented Jan 2, 2025

Version

22.11.0

Platform

Microsoft Windows NT 10.0.22631.0 x64

Subsystem

FS

What steps will reproduce the bug?

While trying to delete a folder without permissions to delete the content of the folder fs.rm takes huge amounts of RAM with potential OOM-Exceptions down the road.

Steps to reproduce:

  1. Create a complex folder tree (see following script as an example)
  2. Ensure user that executes fs.rm has permission to delete rootfolder but does not have permissions to delete content of the rootfolder.
  3. Execute Deletion Script

The testscript did not result in an OOM-exception for me (it stopped at ~8gb RAM usage). You can just create more files to run into an OOM eventually (it broke in production with an OOM for us).

Create data folder:

import { randomUUID } from "crypto";
import { mkdir, writeFile } from "fs/promises";
import { userInfo } from "os";
import { join } from "path";

const parentPath = "D:\\testData\\permission";

for (let i = 0; i < 1_000_000; i++) {
    const uuid = randomUUID();
    const folderPath = join(parentPath, uuid.slice(0, 2), uuid.slice(2, 4), uuid);
    await mkdir(folderPath, {recursive: true, mode: 744});
    await writeFile(join(folderPath, "first"), "1", {mode: 744});
    await writeFile(join(folderPath, "second"), "1", {mode: 744});
    await writeFile(join(folderPath, "third"), "1", {mode: 744});
}

Executing Deletion:

import { rm } from "fs/promises";
const parentPath = "D:\\testData\\permission";

await rm(parentPath, {recursive: true});

How often does it reproduce? Is there a required condition?

As long as enough files/folders are in the to be deleted folder and corresponding permission issues exists the bug reproduces.

What is the expected behavior? Why is that the expected behavior?

Trying to delete a folder should not result in an OOM. Here: it should fail because of permission issues.

What do you see instead?

Huge memory consumption until OOM eventually (with enough content in the folder)

Additional information

No response

@aduh95 aduh95 changed the title fs.rm recursive on a huge directory-tree with missing permissions can result in OOM fs.promises.rm recursive on a huge directory-tree with missing permissions can result in OOM Jan 2, 2025
@viyaha
Copy link
Author

viyaha commented Jan 2, 2025

Memory Consumption is not only happening for fs.promises.rm, but for fs.rm also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant