Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Very weird fs.unlink() behavior with file that is locked by another process #7164

@bpasero

Description

@bpasero

Hi,

I am hunting down an issue which I believe is wrong node.js behavior that reproduces in latst node 0.10.26. I am on Windows and I wrote a small node program that simply tries to delete a file that is used by another process (in this case another node process). The delete actually succeeds for the file although the file is in use. However, a call to fs.readDir() shows me the file still exists. Finally, trying to stat it now results in an EPERM error (Error: EPERM, operation not permitted). I am then in a state where I have to kill the process that locks the file to actually remove it from disk.

The real issue here is that the delete suceeded in the first place and then brought the file system into a state where readDir() shows the file, but stat() is no longer able to stat it. The right behavior (and btw this is how windows behaves if I try to use the explorer) is to not allow the delete in the first place.

I have created a GitHub repo to reproduce: https://github.com/bpasero/nodejsbug.git

To reproduce:

  • clone the repo
  • in one terminal type "node server.js"
  • in another terminal type "node fsdelete.js"
  • in the same terminal type "node fsreaddir.js" and see the file still shows up
  • now try "node fsstat.js" and see that you cannot stat the file

Thanks for looking into this,
Ben

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions