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.rm] Reports ENOTEMPTY randomly #54561

Closed
SukkaW opened this issue Aug 25, 2024 · 6 comments
Closed

[fs.rm] Reports ENOTEMPTY randomly #54561

SukkaW opened this issue Aug 25, 2024 · 6 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@SukkaW
Copy link

SukkaW commented Aug 25, 2024

Version

v22.5.1

Platform

Darwin Sukka-Macbook-Pro.local 24.0.0 Darwin Kernel Version 24.0.0: Mon Aug 12 21:27:51 PDT 2024; root:xnu-11215.1.10~5/RELEASE_ARM64_T6020 arm64

Subsystem

No response

What steps will reproduce the bug?

I was building a rollup plugin that deletes the output folder/files:

import type { Plugin as RollupPlugin } from 'rollup';
import fsp from 'node:fs/promises';

export function cleandir(): RollupPlugin {
  return {
    name: 'cleandir',
    renderStart: {
      order: 'pre',
      async handler(outputOptions) {
        if (outputOptions.dir) {
          await fsp.rm(outputOptions.dir, { recursive: true, force: true });
          await fsp.mkdir(outputOptions.dir, { recursive: true });
        }
        if (outputOptions.file) {
          await fsp.rm(outputOptions.file, { recursive: true, force: true });
        }
      }
    }
  };
}

But I randomly encounter the following error:

src/index.ts → dist, dist...
[!] (plugin cleandir) Error: ENOTEMPTY: directory not empty, rmdir 'dist'
Error: ENOTEMPTY: directory not empty, rmdir 'dist'


ELIFECYCLE  Command failed with exit code 1.

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

About 1 in 8 times.

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

fsp.rm should never reports ENOTEMPTY: directory not empty

What do you see instead?

Error: ENOTEMPTY: directory not empty, rmdir 'dist'

Additional information

I am running a parallel build inside a relatively large monorepo, which might have many file descriptors opened at once.

@avivkeller
Copy link
Member

avivkeller commented Aug 25, 2024

Hi! Can you make a reproduction without rollup as a dependency? Preferably, without any non-built in dependencies?

Secondly, can you try reproducing in v22.7.0? (Or v22.8.0 depending on when you see this message)

@avivkeller avivkeller added the fs Issues and PRs related to the fs subsystem / file system. label Aug 25, 2024
@SukkaW
Copy link
Author

SukkaW commented Aug 25, 2024

Hi! Can you make a reproduction without rollup as a dependency? Preferably, without any non-built in dependencies?

Since it happens randomly, I guess it might have something to do with many existing opened fs descriptors.

I am trying to extract a minimum reproduction.

@nodejs nodejs deleted a comment Aug 26, 2024
@avivkeller
Copy link
Member

I am trying to extract a minimum reproduction.

Great! Until that is done, it'll be hard to people to see what is going wrong.

@avivkeller avivkeller added the stalled Issues and PRs that are stalled. label Sep 14, 2024
Copy link
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

@avivkeller avivkeller removed the stalled Issues and PRs that are stalled. label Sep 14, 2024
@juanarbol
Copy link
Member

juanarbol commented Oct 31, 2024

This is not a bug, sometimes OS are like that?

If an EBUSY, EMFILE, ENFILE, ENOTEMPTY, or EPERM error is encountered, Node.js will retry the operation with a linear backoff wait of retryDelay milliseconds longer on each try. This option represents the number of retries. This option is ignored if the recursive option is not true. Default: 0.

Please use something like await fsp.rm(outputOptions.dir, { recursive: true, force: true, maxRetries: ANY });

Ref: https://nodejs.org/docs/latest-v22.x/api/fs.html#fspromisesrmpath-options

@juanarbol
Copy link
Member

Closing this, as this is an expected and documented behaviour.

aleclarson added a commit to pg-nano/pg-tmp that referenced this issue Nov 22, 2024
This makes it more resilient against random failure.

See nodejs/node#54561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

4 participants
@juanarbol @avivkeller @SukkaW and others