-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
can the fs module operate on fd's opened by a native add-on? #15433
Comments
I think if you use libuv to obtain the fd, and wrap it appropriately for use in JavaScript like the |
FWIW, I've done this and yes, it works and yes, it turns out to be a bad idea. Your best bet to to use |
As well, it won't work if your add-on - or, more commonly, one of your add-on's libraries - is linked against a different CRT.
|
Thanks to everyone for the feedback.
Will I'm assuming that The reason for asking is I'd like to add support for If converting Windows handles to |
Yes (although any libraries your add-on links against may not be, of course.) |
I tried to open a file from a native add on, just doing this:
That's all the native add on does. It's just there to open the file with Windows' O_DIRECT and O_DSYNC equivalents since these are not yet supported by I get the I thought the native add on would share the static multi-threaded CRT? |
Now that you mention it: add-ons probably inherit the @nodejs/platform-windows Can one of you check that hypothesis? |
Hypothesis checks out. Removing |
@joaocgreis Anything we can do about that? I think ideally we'd want add-ons to use the CRT that's linked with node; i.e., we re-export the CRT's symbols. Are there downsides to that? |
I guess this one is pretty dormant but does anyone know a workaround for this problem? I have the same problem (although in my case I want to pass a pipe handle to (The only way I see this working is if node.exe exports |
Adds uv_open_osfhandle to complete uv_get_osfhandle Ref: nodejs/node#15433 Ref: nodejs/node-addon-api#304
@eriohl with named pipes specifically you have to be very careful, as they have multiple combinations of mode that could make trouble (PIPE_NOWAIT or TYPE_MESSAGE/PIPE_READMODE_MESSAGE) Anyway there's a PR that was already approved for libuv, hopefully it will make it to nodejs soon! |
Adds uv_open_osfhandle to complete uv_get_osfhandle Ref: nodejs/node#15433 Ref: nodejs/node-addon-api#304
Adds uv_open_osfhandle to complete uv_get_osfhandle Ref: nodejs/node#15433 Ref: nodejs/node-addon-api#304 PR-URL: #1927 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Notable changes: - Restores compatibility with the old IPC protocol. - Adds uv_open_osfhandle(). - Adds uv_os_{get,set}priority(). PR-URL: nodejs#22365 Fixes: nodejs#21671 Fixes: nodejs#15433 Refs: nodejs#21675 Refs: nodejs/node-addon-api#304 Refs: nodejs/abi-stable-node#318 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable changes: - Restores compatibility with the old IPC protocol. - Adds uv_open_osfhandle(). - Adds uv_os_{get,set}priority(). PR-URL: #22365 Fixes: #21671 Fixes: #15433 Refs: #21675 Refs: nodejs/node-addon-api#304 Refs: nodejs/abi-stable-node#318 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable changes: - Restores compatibility with the old IPC protocol. - Adds uv_open_osfhandle(). - Adds uv_os_{get,set}priority(). PR-URL: #22365 Fixes: #21671 Fixes: #15433 Refs: #21675 Refs: nodejs/node-addon-api#304 Refs: nodejs/abi-stable-node#318 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable changes: - Restores compatibility with the old IPC protocol. - Adds uv_open_osfhandle(). - Adds uv_os_{get,set}priority(). PR-URL: nodejs#22365 Fixes: nodejs#21671 Fixes: nodejs#15433 Refs: nodejs#21675 Refs: nodejs/node-addon-api#304 Refs: nodejs/abi-stable-node#318 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable changes: - Restores compatibility with the old IPC protocol. - Adds uv_open_osfhandle(). - Adds uv_os_{get,set}priority(). Backport-PR-URL: #24103 PR-URL: #22365 Fixes: #21671 Fixes: #15433 Refs: #21675 Refs: nodejs/node-addon-api#304 Refs: nodejs/abi-stable-node#318 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Is it safe to use a native add-on to open a file, and then pass the file descriptor to methods of the
fs
module?My concern is especially for Windows. Will everything just work because Libuv uses
uv__get_osfhandle
?Usually, people want to open a file in Node, and pass the file descriptor to a native add-on and this used to give problems on Windows before
uv__get_osfhandle
was made public.The text was updated successfully, but these errors were encountered: