-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
node:fs
APIs are not actually using file descriptors
#23012
Comments
node:worker_threads
don't share resources with main Instancenode:worker_threads
don't share resources with main instance
This is a bug in |
node:worker_threads
don't share resources with main instancenode:fs
APIs are not actually using file descriptors
I'm not sure, if I'm able to understand your explanation. Right now all operations in And if I got it right, you argue, that the |
No, they are not. Resource ID is not a File Descriptor. Even though they are both number, the
We might still use resource table to properly clean up opened files, but we first need to fix the APIs to return proper OS file descriptors instead of resource ids. This is gonna be a big refactor that will take about two weeks and needs to be handled by the core team. |
I never thought, that #[op2(fast)]
pub fn op_fs_get_fd(
state: &mut OpState,
#[smi] rid: ResourceId,
) -> Result<i32, AnyError>{
let file = FileResource::get_file(state, rid)?;
let fd = match file.backing_fd() {
Some(fd) => fd,
None => return Err(generic_error("fd not found")),
};
Ok(fd)
} That's why I'm rather confused about your explanation, that file descriptors aren't accessible via this RIDs. The question, how these handlers or entire resource entries should be shared/replicated/transferred between threads/workers without fear, looks much more difficile to me. Nevertheless, I really understand that this topic is indeed a rather complex one and it has to be handled very carefully by those, who are really familiar with its design and security implications. |
A bunch of tests were disabled in #25285 for these APIs as they showed incorrect behavior using resource IDs instead of file descriptors. |
Version: upstream (2f7b966)
deno
seems to show a significant different behavior when it comes to accessibility of resources between main instance and workers. Innode
andbun
you can open a file, send the file descriptor resp. RID to the worker and access its content in this other context. Using deno, you will get just anBadResource
Error. The received RID isn't present in the resource table of the client.Here a small demonstration script:
the output using
deno
:on
node
:and
bun
:Although I understand
deno
s radical different answer in this case very well, because it helps to prevent all sort of thread related troubles, it's still a significant different behavior resp. incompatibility.The
deno_core
docu states aboutResources
:I'm not sure if this explanation inevitable applies to
node:worker_threads
, therefore I'm asking here, how we should work around this incompatibility?Otherwise I would have to write rather complex adaptations for an existing software to bypass this differences in behavior (bytecodealliance/jco#400).
The text was updated successfully, but these errors were encountered: