| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
Sorry, something went wrong.
|
@nodejs/fs |
Sorry, something went wrong.
|
@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 FileHandle that has pending operations. |
Sorry, something went wrong.
Yeah, I agree – that sounds like the best approach to me 👍 |
Sorry, something went wrong.
Sorry, something went wrong.
|
It would likely be good to add a comment to the fs.md documentation for FileHandle.close() that pending operations will be completed. |
Sorry, something went wrong.
Co-authored-by: James M Snell <jasnell@gmail.com>
Fixed |
Sorry, something went wrong.
Co-authored-by: James M Snell <jasnell@gmail.com>
Sorry, something went wrong.
Sorry, something went wrong.
This can currently be triggered when posting a closing FileHandle. Refs: nodejs#34746 (comment)
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>
| Back | FazBrowse Home | New Git URL |
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