Skip to content

fs.rmSync() not releasing file handles #39946

Description

@andrewhodel

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

Activity

  1. andrewhodel commented on Aug 30, 2021

    @andrewhodel
    Author
  2. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on Aug 30, 2021
  3. bcoe commented on Sep 3, 2021

    @bcoe
    Contributor

    @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}));
    
  4. andrewhodel commented on Sep 3, 2021

    @andrewhodel
    Author
  5. bcoe commented on Sep 3, 2021

    @bcoe
    Contributor

    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.

  6. andrewhodel commented on Sep 3, 2021

    @andrewhodel
    Author
  7. bcoe commented on Sep 3, 2021

    @bcoe
    Contributor

    @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?

  8. andrewhodel commented on Sep 3, 2021

    @andrewhodel
    Author
  9. andrewhodel commented on Sep 3, 2021

    @andrewhodel
    Author
  10. andrewhodel commented on Sep 13, 2021

    @andrewhodel
    Author
  11. bcoe commented on Sep 13, 2021

    @bcoe
    Contributor

    @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.

  12. andrewhodel commented on Sep 13, 2021

    @andrewhodel
    Author
  13. bcoe commented on Sep 13, 2021

    @bcoe
    Contributor

    @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).

  14. bcoe commented on Sep 13, 2021

    @bcoe
    Contributor

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

  15. andrewhodel commented on Sep 13, 2021

    @andrewhodel
    Author
  16. bcoe commented on Sep 13, 2021

    @bcoe
    Contributor

    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).

  17. bcoe commented on Sep 20, 2021

    @bcoe
    Contributor

    @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?
  18. andrewhodel commented on Sep 20, 2021

    @andrewhodel
    Author
  19. andrewhodel commented on Sep 20, 2021

    @andrewhodel
    Author
  20. andrewhodel commented on Oct 5, 2021

    @andrewhodel
    Author
  21. andrewhodel commented on Oct 18, 2021

    @andrewhodel
    Author
  22. bcoe commented on Oct 27, 2021

    @bcoe
    Contributor

    @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.

  23. andrewhodel commented on Oct 27, 2021

    @andrewhodel
    Author
  24. andrewhodel commented on Oct 27, 2021

    @andrewhodel
    Author
  25. andrewhodel commented on Oct 27, 2021

    @andrewhodel
    Author
  26. benjamingr commented on Oct 27, 2021

    @benjamingr
    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.

  27. andrewhodel commented on Oct 27, 2021

    @andrewhodel
    Author
  28. andrewhodel commented on Oct 27, 2021

    @andrewhodel
    Author
  29. andrewhodel commented on Oct 27, 2021

    @andrewhodel
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions