-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 streams leak fd on invalid argument #35168
Comments
Hi @ronag , I worked out a solution that seems to solve the issue, I just wanted to run my thinking process by you to ensure I am on the right track. I am catching the error that is thrown from validateInteger, executing fs.close() on the fd variable passed into the ReadStream/WriteStream constructor, then re-throwing the error that was caught. Let me know if my solution here is incorrect or if you have any advice. Thanks. |
@ronag Should I be handling the error from fs.close callback in any specific way? Or should I be using the synchronous method |
@dylanelliott27 create a PR and we can discuss it there |
@ronag I don't think this is the right problem to be solved at node level but actually, the program using the createReadStream has the fd leak problem. At least considering the snippet you have put in the description. I went ahead and checked if we are leaking fd in the case when the path argument is valid and the start argument is invalid. Since in that scenario, the caller has no control over the opened file descriptor. But that's not the case either. And here's what I did to confirm that:
If the file was being read before argument validation then it would have thrown permission denied, but the test code threw the "Invalid argument" error. Hence we can conclude that node is not leaking fd. |
I don't quite follow...
It is leaking a fd since |
@ronag There's nothing special about |
There is something special... streams take ownership of the fd and closes it, while e.g. |
You could argue either way in regards to what to expect in this specific case. I think it's cleaner if it closes it otherwise you always should wrap |
Not necessarily. You are not supposed to pass invalid arguments to |
Hm, fair enough. |
The text was updated successfully, but these errors were encountered: