Repository navigation
fs.rmSync() not releasing file handles #39946
Description
Activity
andrewhodel commented
on Aug 30, 2021 on Aug 30, 2021 · Hidden as spamAuthorshow commentMore actions- addedfsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
on Aug 30, 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}));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 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 commented
on Sep 3, 2021 on Sep 3, 2021 via email · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Sep 3, 2021 on Sep 3, 2021 via email · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Sep 13, 2021 on Sep 13, 2021 · Hidden as spamAuthorshow commentMore actions@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 commented
on Sep 13, 2021 on Sep 13, 2021 · Hidden as spamAuthorshow commentMore actions@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).
@andrewhodel is there a docker container we could perhaps use alternatively? then I can try pulling it locally and reproducing.
andrewhodel commented
on Sep 13, 2021 on Sep 13, 2021 · Hidden as spamAuthorshow commentMore actionsI 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).
@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/LinuxOne 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?
- ssh into AWS instance?
- execute with
nodeI assume?
andrewhodel commented
on Sep 20, 2021 on Sep 20, 2021 · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Sep 20, 2021 on Sep 20, 2021 · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Oct 18, 2021 on Oct 18, 2021 · Hidden as spamAuthorshow commentMore actions@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 commented
on Oct 27, 2021 on Oct 27, 2021 via email · Hidden as abuseAuthorshow commentMore actionsandrewhodel commented
on Oct 27, 2021 on Oct 27, 2021 via email · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Oct 27, 2021 on Oct 27, 2021 · Hidden as spamAuthorshow commentMore actionsWho'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.
Reacted by maja42andrewhodel commented
on Oct 27, 2021 on Oct 27, 2021 via email · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Oct 27, 2021 on Oct 27, 2021 via email · Hidden as spamAuthorshow commentMore actionsandrewhodel commented
on Oct 27, 2021 on Oct 27, 2021 via email · Hidden as spamAuthorshow commentMore actions
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
sudo lsof +L1
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
dureports less disk space being used thatdf.Additional information
No response