-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: guard against undefined behavior #34746
Conversation
Calling close on a file description which is currently in use is undefined behavior due to implementation details in libuv. Add a guard against this when using FileHandle.
03ee3d5
to
bc670bd
Compare
6169687
to
107f508
Compare
4a3099a
to
711653a
Compare
711653a
to
fd5ca60
Compare
@nodejs/fs |
@addaleax ... This brought an edge case to mind that I'm not sure how we're handling... What should happen in the following case 'use strict';
const fs = require('fs');
const { Worker, workerData, isMainThread } = require('worker_threads');
if (isMainThread) {
async function foo() {
const fh = await fs.promises.open(__filename);
const buffer = Buffer.alloc(1000);
// Not awaiting...
const p = fh.read(buffer, 0, 1000);
// Transferring the FileHandle while there's potentially
// an outstanding async operation on it.
const w = new Worker(__filename, {
workerData: fh,
transferList: [fh]
});
// Then awaiting...
await p;
return buffer.toString();
}
foo().then(console.log);
} else {
workerData.close();
} First immediate thought is that we should throw if attempting to transfer a |
Yeah, I agree – that sounds like the best approach to me 👍 |
It would likely be good to add a comment to the fs.md documentation for |
Co-authored-by: James M Snell <jasnell@gmail.com>
Fixed |
Co-authored-by: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: nodejs#34746 (comment)
Landed in a0f87aa |
Calling close on a file description which is currently in use is undefined behavior due to implementation details in libuv. Add a guard against this when using FileHandle. PR-URL: #34746 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: nodejs#34746 (comment) PR-URL: nodejs#34766 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Calling close on a file description which is currently in use is undefined behavior due to implementation details in libuv. Add a guard against this when using FileHandle. PR-URL: #34746 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Backport-PR-URL: #34814 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Calling close on a file description which is currently in use is undefined behavior due to implementation details in libuv. Add a guard against this when using FileHandle. PR-URL: #34746 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Backport-PR-URL: #34814 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Backport-PR-URL: #34814 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Backport-PR-URL: #34814 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Calling close on a file description which is currently in use is
undefined behavior due to implementation details in libuv. Add
a guard against this when using FileHandle.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes