-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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.stat returns a size of 0 for /proc/* files #43669
Comments
Returning zero agrees with the file size reported by the |
That's indeed how /proc files work. Closing as not a bug. |
Hi @mscdex @bnoordhuis thank you very much for your response! Any idea on how to tell the difference between a file like this and a file with an actual zero size? Should the docs at https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#statssize be updated to note that it may return zero though the file actually does have contents? Perhaps including the same note in the Node.js docs that libuv does in http://docs.libuv.org/en/v1.x/fs.html
|
@dougwilson If node exposed an Otherwise you could just try opening the file and start reading it. Obviously in this case if you're sending this as an HTTP request/response you'd need to stream it instead of setting a |
Thanks. What about updating the Node.js docs? Does the suggestion I put above make sense? I assume that Node.js has that libuv behavior, but just wanted to confirm before opening a pr to copy that note into the Node.js docs. |
AFAIK it's not an OS issue, but a filesystem issue. I wouldn't be surprised if the same situation could happen with other filesystem types in various scenarios. |
I don't mind documenting it. It can double as a warning that stat-then-read is a pretty broken approach to slurping files because the file can change between stat and read. (Not that I'm pointing any fingers. Node had the same bug at one point.) |
Right, for sure. I'm thinking the following note would suffice:
|
Refs: nodejs/node#43669 PR-URL: nodejs/node#43690 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
Version
v16.15.1
Platform
Linux ubuntu 5.13.0-48-generic #54~20.04.1-Ubuntu
Subsystem
fs
What steps will reproduce the bug?
You can see the result by simply running the following code.
How often does it reproduce? Is there a required condition?
There is no required condition, it always returns the same result.
What is the expected behavior?
It was expected to return actual file size.
What do you see instead?
Instead of actual file size, it shows size as 0.
Additional information
This is valid for files under /proc directory. fs.stat returns size as 0 for /proc/meminfo, /proc/cpuinfo, /proc/version and other files.
Below code from nodejs-procfs with a small modification, is able to return actual file size.
The text was updated successfully, but these errors were encountered: