-
Notifications
You must be signed in to change notification settings - Fork 30k
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
fsPromises.truncate doesn't close fd. #34189
Comments
Could you show the code to reproduce? |
I'm not able to reproduce. As an example:
No warnings. @sheepa I'm going to close this but I can reopen if you post steps to reproduce. |
The following code give me |
@bnoordhuis... closing this was premature. This is an issue that was fixed in master in eadc385 but it does not look like the fix was backported to 12.x yet. See... https://github.com/nodejs/node/blob/v12.x/lib/internal/fs/promises.js#L307-L309
|
@sheepa ... I'll be opening a PR to backport the fix to 12.x soon but it will take a while for that to land in a release. You can work around the issue for now by using the async function myTruncate(path, len) {
const fd = await open(path, 'r+');
return ftruncate(fd, len).finally(fd.close.bind(fd));
} |
eadc385 references #28858 as the PR and that's marked semver-major so it will be ignored by our tooling (e.g. branch-diff) and processes when evaluating what could be backported. |
@richardlau ... yeah, I spotted that. This one commit is not semver-major. I'm working on a backport PR now for 12.x but github is giving me the Unicorn of Sadness at the moment. Will open as soon as the site becomes responsive again |
PR opened! |
What steps will reproduce the bug?
fsPromises.truncate(path) will result in a warning a few seconds later:
(node:1387179) Warning: Closing file descriptor 22 on garbage collection
- Using the callback truncateawait new Promise((res, rej) => { fs.truncate(file, (err, ret) => { if(err) rej(err); else res(ret) }) })
works fine without such warning.How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior?
Not having this warning.
What do you see instead?
Additional information
The text was updated successfully, but these errors were encountered: