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.rmdirSync stuck in busy-loop on Windows #34580

Closed
darkk opened this issue Jul 31, 2020 · 5 comments
Closed

fs.rmdirSync stuck in busy-loop on Windows #34580

darkk opened this issue Jul 31, 2020 · 5 comments
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@darkk
Copy link

darkk commented Jul 31, 2020

  • Version: v12.18.3
  • Platform: Windows 10, 64-bit, Version 10.0.17763.1339
  • Subsystem: fs

What steps will reproduce the bug?

const fs = require('fs');
const { tmpdir } = require('os');
const { join } = require('path');

function rmdirRecursiveSync() {
  const root = fs.mkdtempSync(join(tmpdir(), 'fs-'));

  const middle = join(root, 'middle');
  fs.mkdirSync(middle);
  fs.mkdirSync(join(middle, 'leaf')); // make `middle` non-empty
  fs.chmodSync(middle, 0);

  fs.rmdirSync(root, { recursive: true });
}

rmdirRecursiveSync();

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

The bug reliably reprodices on windows.

What is the expected behavior?

I expect fs.rmdirSync() to fail the same way as fs.rmdir() does. But it does not.

Linux produces expected behavior throwing an error:

Error: EACCES: permission denied, scandir '/tmp/fs-0wJvqH/middle'
    at readdirSync (fs.js:948:3)
    at _rmdirSync (internal/fs/rimraf.js:242:7)
    at rimrafSync (internal/fs/rimraf.js:191:7)
    at internal/fs/rimraf.js:245:9
    at Array.forEach (<anonymous>)
    at _rmdirSync (internal/fs/rimraf.js:242:45)
    at rimrafSync (internal/fs/rimraf.js:191:7)
    at Object.rmdirSync (fs.js:838:12)
    at rmdirRecursiveSync (/…/rmdirRecursiveSync.js:13:6)
    at Object.<anonymous> (/…/rmdirRecursiveSync.js:16:1) {
  errno: -13,
  syscall: 'scandir',
  code: 'EACCES',
  path: '/tmp/fs-0wJvqH/middle'
}

Windows async fs.rmdir({recursive:true}) instead of fs.rmdirSync() gives expected behavior as well, it passes an error to the callback:

[Error: EPERM: operation not permitted, rmdir 'C:\…\Temp\fs-vJZvJ7\middle'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'rmdir',
  path: 'C:\\…\\Temp\\fs-vJZvJ7\\middle'
}

What do you see instead?

Node process is stuck with 100%-CPU busy-loop.

Additional information

Process Monitor suggests a busy-loop while endlessly retrying to delete a file, the log excerpt is pasted below:

"Time of Day","Operation","Path","Result","Detail"
...
"2:02:16.0518106 PM","SetDispositionInformationFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","CANNOT DELETE","Delete: True"
"2:02:16.0518663 PM","CloseFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS",""
"2:02:16.0527830 PM","CreateFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Desired Access: Read Data/List Directory, Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open For Backup, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"2:02:16.0528985 PM","QueryDirectory","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","0: ., 1: .., FileInformationClass: FileDirectoryInformation"
"2:02:16.0529916 PM","QueryDirectory","C:\…\Temp\fs-Y3XBJk\middle\leaf","NO MORE FILES",""
"2:02:16.0530399 PM","CloseFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS",""
"2:02:16.0543568 PM","CreateFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open For Backup, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"2:02:16.0544702 PM","QueryAllInformationFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","BUFFER OVERFLOW","CreationTime: 7/31/2020 12:40:00 PM, LastAccessTime: 7/31/2020 2:02:14 PM, LastWriteTime: 7/31/2020 12:40:00 PM, ChangeTime: 7/31/2020 12:40:00 PM, FileAttributes: RD, AllocationSize: 0, EndOfFile: 0, NumberOfLinks: 1, DeletePending: False, Directory: True, IndexNumber: 0x100000007cc38, EaSize: 0, Access: Read Attributes, Synchronize, Position: 0, Mode: Synchronous IO Non-Alert, AlignmentRequirement: Word"
"2:02:16.0545350 PM","QueryInformationVolume","C:\…\Temp\fs-Y3XBJk\middle\leaf","BUFFER OVERFLOW","VolumeCreationTime: 3/19/2019 10:40:48 PM, VolumeSerialNumber: B4A6-FEC6, SupportsObjects: True, VolumeLabel: WinǴ"
"2:02:16.0545884 PM","CloseFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS",""
"2:02:16.0554352 PM","CreateFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Desired Access: Read Attributes, Delete, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Open For Backup, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"2:02:16.0555403 PM","QueryAttributeTagFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Attributes: RD, ReparseTag: 0x0"
"2:02:16.0555972 PM","SetDispositionInformationFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","CANNOT DELETE","Delete: True"
"2:02:16.0557121 PM","CloseFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS",""
"2:02:16.0565707 PM","CreateFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Desired Access: Read Data/List Directory, Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open For Backup, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"2:02:16.0566833 PM","QueryDirectory","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","0: ., 1: .., FileInformationClass: FileDirectoryInformation"
"2:02:16.0568326 PM","QueryDirectory","C:\…\Temp\fs-Y3XBJk\middle\leaf","NO MORE FILES",""
"2:02:16.0569022 PM","CloseFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS",""
"2:02:16.0572185 PM","CreateFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open For Backup, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"2:02:16.0573269 PM","QueryAllInformationFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","BUFFER OVERFLOW","CreationTime: 7/31/2020 12:40:00 PM, LastAccessTime: 7/31/2020 2:02:14 PM, LastWriteTime: 7/31/2020 12:40:00 PM, ChangeTime: 7/31/2020 12:40:00 PM, FileAttributes: RD, AllocationSize: 0, EndOfFile: 0, NumberOfLinks: 1, DeletePending: False, Directory: True, IndexNumber: 0x100000007cc38, EaSize: 0, Access: Read Attributes, Synchronize, Position: 0, Mode: Synchronous IO Non-Alert, AlignmentRequirement: Word"
"2:02:16.0573616 PM","QueryInformationVolume","C:\…\Temp\fs-Y3XBJk\middle\leaf","BUFFER OVERFLOW","VolumeCreationTime: 3/19/2019 10:40:48 PM, VolumeSerialNumber: B4A6-FEC6, SupportsObjects: True, VolumeLabel: WinǴ"
"2:02:16.0573888 PM","CloseFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS",""
"2:02:16.0576180 PM","CreateFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Desired Access: Read Attributes, Delete, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Open For Backup, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"2:02:16.0576756 PM","QueryAttributeTagFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","SUCCESS","Attributes: RD, ReparseTag: 0x0"
"2:02:16.0577024 PM","SetDispositionInformationFile","C:\…\Temp\fs-Y3XBJk\middle\leaf","CANNOT DELETE","Delete: True"
...
@darkk
Copy link
Author

darkk commented Jul 31, 2020

The busy-loop is reproduced on Linux if fs.chmodSync(middle, 0555) is used instead of fs.chmodSync(middle, 0).

@Trott
Copy link
Member

Trott commented Aug 29, 2020

/ping @nodejs/platform-windows @nodejs/fs

@bnoordhuis bnoordhuis added confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. labels Aug 31, 2020
@bnoordhuis
Copy link
Member

I can confirm. Easy fix:

diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js
index e88dd9697b..bdf731ba04 100644
--- a/lib/internal/fs/rimraf.js
+++ b/lib/internal/fs/rimraf.js
@@ -229,6 +229,8 @@ function _rmdirSync(path, options, originalErr) {
   } catch (err) {
     if (err.code === 'ENOENT')
       return;
+    if (err.code === 'EACCES')
+      throw err;
     if (err.code === 'ENOTDIR')
       throw originalErr;
 

Someone should probably take a long, hard look at that function though. It recognizes a few error codes and ignores all others. Not a recipe for success.

@Lxxyx
Copy link
Member

Lxxyx commented Dec 18, 2020

Tested in 4 Node versions.

Platform: Windows 10, 64-bit, Version 19042.685

  • 12.20.0: The problem still exists
  • 14.15.3: No problem
  • 15.4.0: No problem
  • 16.0.0-pre(build from master): No Problem

image

@Trott Trott added the v12.x label Dec 23, 2020
RaisinTen added a commit to RaisinTen/node that referenced this issue Jan 6, 2021
RaisinTen added a commit to RaisinTen/node that referenced this issue Jan 27, 2021
RaisinTen added a commit to RaisinTen/node that referenced this issue Mar 1, 2021
RaisinTen added a commit to RaisinTen/node that referenced this issue Mar 26, 2021
@jasnell jasnell added the windows Issues and PRs related to the Windows platform. label Apr 30, 2021
@marko-knoebl
Copy link

marko-knoebl commented May 5, 2021

FYI, I had this problem in node 14.4.0 as well. Updated to 14.16.1 and it's working as expected.

EDIT:

Wait, no! ... I'm actually encountering a different (worse?) problem in node 14.16.1 - it's failing silently!

So when running the code from the original bug report:

expected behavior: fails with an error

behavior in node 14.4.0: infinite loop

behavior in node 14.16.1: fails without error

@Lxxyx what did you test for when testing various node versions? Did you test for an error?

RaisinTen added a commit to RaisinTen/node that referenced this issue May 18, 2021
Linkgoron added a commit to Linkgoron/node that referenced this issue May 19, 2021
fix rmsync swallowing errors instead of throwing them.

fixes: nodejs#38683
fixes: nodejs#34580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
6 participants