-
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: improve readFileSync
with file descriptors
#49691
Conversation
Test failures look related. Correctness issue: file descriptors are int32, not uint32 (also on Windows, because they go through libuv.) |
@bnoordhuis We validate file descriptors on |
Apparently that goes back to commit 0803962 from 2015... still wrong though. :-) (Mostly harmless although technically signed integer overflow is UB in C++.) |
Nice find! I'll update the pull request. @RafaelGSS I'm getting some weird failed test cases where
|
0dfcfa4
to
de56591
Compare
6fea27f
to
a415654
Compare
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1413
|
@nodejs/cpp-reviewers @nodejs/fs Can you review? |
CHECK_EQ(0, uv_fs_close(nullptr, &req, file, nullptr)); | ||
FS_SYNC_TRACE_END(close); | ||
} | ||
uv_fs_req_cleanup(&req); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For correctness reasons this ought to be done after the uv_fs_read() call on line 2590. It works okay now because libuv doesn't allocate for a single buffer (i.e. this cleanup call is a no-op) but that's a lucky accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean that on every while loop iteration (for uv_fs_read
), we need to call uv_fs_req_cleanup
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Landed in f16f41c |
@anonrig Please always post the benchmark CI results in the PR (for example by editing the comment with the link like I just did). Jenkins results are not permanent. |
PR-URL: #49691 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
PR-URL: #49691 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
PR-URL: nodejs#49691 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Fix a file permissions regression when `fs.readFileSync()` is called in append mode on a file that does not already exist introduced by the fast path for utf8 encoding. PR-URL: #52101 Fixes: #52079 Refs: #49691 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Fix a file permissions regression when `fs.readFileSync()` is called in append mode on a file that does not already exist introduced by the fast path for utf8 encoding. PR-URL: nodejs#52101 Fixes: nodejs#52079 Refs: nodejs#49691 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Fix a file permissions regression when `fs.readFileSync()` is called in append mode on a file that does not already exist introduced by the fast path for utf8 encoding. PR-URL: #52101 Fixes: #52079 Refs: #49691 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Fix a file permissions regression when `fs.readFileSync()` is called in append mode on a file that does not already exist introduced by the fast path for utf8 encoding. PR-URL: #52101 Fixes: #52079 Refs: #49691 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
This particular change applies to:
fs.readFileSync(fs.openSync(__filename), 'utf8')
My local benchmarks are as follows:
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1413