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.rmSync() not releasing file handles #39946

Closed
andrewhodel opened this issue Aug 30, 2021 · 28 comments
Closed

fs.rmSync() not releasing file handles #39946

andrewhodel opened this issue Aug 30, 2021 · 28 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@andrewhodel
Copy link

andrewhodel commented Aug 30, 2021

Version

v14.15.4

Platform

Linux ip-10-0-165-79.ec2.internal 4.14.238-182.422.amzn2.x86_64 #1 SMP Tue Jul 20 20:35:54 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

fs

What steps will reproduce the bug?

node process.js

fs.rmSync('/hash.zip');

setInterval(function() {
  console.log('l');
}, 5000);

sudo lsof +L1

COMMAND     PID     USER   FD   TYPE DEVICE   SIZE/OFF NLINK    NODE NAME
node      11805     root   31w   REG  202,1 4228388441     0   23903 /2196b4e05a48154156ac87d906dc9efecb281456b87ac22016b243d273796e9ca8df590f1760228fe5bb71b1b5f8c5430ca87ff1e299c4d6f852dd0276a27dea.zip (deleted)
node      11805     root   39w   REG  202,1 4228227826     0   69164 /97d5140e9ea7938a650f2128385437e98f4257b28d3ad9b94efd835ea2fcb48ca291bceb22539e9197e2f0063de244e3133a535753d6d5b4721355ddd66e9ac4.zip (deleted)
node      11805     root   44w   REG  202,1 4228200493     0   69114 /0d971d55a946e1c339e8c05c80c1c24aa67034b75e8f4a66295c256b83d9948f2adb48d7e2f017fa4d54c95cf14633badd0ecb76583b01317f451e1ae7a78a3b.zip (deleted)
node      11805     root   46w   REG  202,1 4228227826     0   69164 /97d5140e9ea7938a650f2128385437e98f4257b28d3ad9b94efd835ea2fcb48ca291bceb22539e9197e2f0063de244e3133a535753d6d5b4721355ddd66e9ac4.zip (deleted)
node      11805     root   47w   REG  202,1 4228269639     0   69101 /21283b41d93b6633149a1872a64c8f8204a43b2b9e76608e7bda97dbca1ea0c449826754d293ca8c275d367faa98015710e6755cfc611b9e65afcb0e0edcb8b4.zip (deleted)
node      11805     root   49w   REG  202,1 4228269639     0   69101 /21283b41d93b6633149a1872a64c8f8204a43b2b9e76608e7bda97dbca1ea0c449826754d293ca8c275d367faa98015710e6755cfc611b9e65afcb0e0edcb8b4.zip (deleted)

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

Every time.

What is the expected behavior?

I would expect that fs.rmSync() would release the file handle.

What do you see instead?

The file handle remains open and as such du reports less disk space being used that df.

Additional information

No response

@andrewhodel

This comment was marked as spam.

@Mesteery Mesteery added the fs Issues and PRs related to the fs subsystem / file system. label Aug 30, 2021
@bcoe
Copy link
Contributor

bcoe commented Sep 3, 2021

@andrewhodel I'm curious, does it happen if you do something like:

cp.exec('unzip -d /upload_file_name + '.zip', {shell: true, cwd: '/'}, async function (error, stdout, stderr) {
	// remove the zip file
	await fs.promises.rm('/' + this.upload_file_name + '.zip');
}.bind({upload_file_name: upload_file_name}));

@andrewhodel

This comment was marked as spam.

@bcoe
Copy link
Contributor

bcoe commented Sep 3, 2021

I am too frustrated to test it considering it should not be relevant and is conflating (inversely so) to the real issue.

@andrewhodel I'm sorry that you're feeling frustrated.

It's relevant because it helps isolate the problem to whether it's happening only in the synchronous code path, or if it's a systemic issue with both implementations.

@andrewhodel

This comment was marked as spam.

@bcoe
Copy link
Contributor

bcoe commented Sep 3, 2021

@andrewhodel I understand you're frustrated. But please understand that Node.js is open source and worked on by volunteers. I'm taking time out of my own busy work schedule to triage this bug.

The following code does not reproduce for me on OSX:

const fs = require('fs')

fs.rmSync('foo.txt');

setInterval(function() {
  console.log('l');
}, 5000);

So the behavior must be cropping up only in some environments. #39853 describes similar behavior, also on GNU/Linux.

@andrewhodel in your case, does the file handle also release after the process exits?

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@bcoe
Copy link
Contributor

bcoe commented Sep 13, 2021

@andrewhodel I'm afraid no updates, I'll do my best to submit a failing test shortly, so we have a starting point. My hope is the issue crops up in at least one of Node.js' test environments.

@andrewhodel

This comment was marked as spam.

@bcoe
Copy link
Contributor

bcoe commented Sep 13, 2021

@andrewhodel this could definitely help me debug 👍 before I bother you to do so though, let me write a test that reproduces it, and we can see if it happens in any of the test environments (then we know we've squashed the issue once that test starts passing).

@bcoe
Copy link
Contributor

bcoe commented Sep 13, 2021

@andrewhodel is there a docker container we could perhaps use alternatively? then I can try pulling it locally and reproducing.

@andrewhodel

This comment was marked as spam.

@bcoe
Copy link
Contributor

bcoe commented Sep 13, 2021

I will update this thread when I've written a failing test, I'll aim for later this week 👍 (I have Thursday mornings carved out for OSS work).

@bcoe
Copy link
Contributor

bcoe commented Sep 20, 2021

@andrewhodel I tested with Amazon's lambda base image and unfortunately it didn't reproduce, this is the container I'm running:

Linux 297e8b498d12 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

One thing that jumped out at me, I notice in your sample code does not require('fs');, which for me results in:

ReferenceError: fs is not defined

When executing the script. How do you execute the sample code you shared?

  1. ssh into AWS instance?
  2. execute with node I assume?

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@bcoe
Copy link
Contributor

bcoe commented Oct 27, 2021

@andrewhodel unfortunately have no cycles to work on this.

If you made an instance I could SSH into, I would take a look. The problem is, I can't guarantee it won't take me a couple weeks; and I don't want you to be running up an EC2 bill.

@andrewhodel

This comment has been minimized.

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@benjamingr
Copy link
Member

@andrewhodel

Who's so poor that this is a problem?

Hey - I am happy the issue is resolved - in the future I would appreciate if you please don't leave these sort of comments in the project :)

Feel free to self-moderate that comment and I'll delete this one.

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

@andrewhodel

This comment was marked as spam.

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