fix(ext/node): return real OS file descriptors from node:fs APIs#31965
fix(ext/node): return real OS file descriptors from node:fs APIs#31965fraidev wants to merge 2 commits intodenoland:mainfrom
Conversation
9923810 to
95cca70
Compare
6fd1d7e to
92c32cd
Compare
these statements seem inconsistent |
| #[cfg(unix)] | ||
| #[op2(fast)] | ||
| #[smi] | ||
| pub fn op_node_dup_fd( |
There was a problem hiding this comment.
This is a dangerous op. It allows you to create a Resource for any open fd that Deno has (e.g sqlite DB)
There was a problem hiding this comment.
Indeed, what do you think about separating the internal FDs? A separate set for (SQLite, etc.)
There was a problem hiding this comment.
I think the FD -> resource map should be in Rust so we can verify the fd exists in the map before calling dup() on it
There was a problem hiding this comment.
FDs are assigned by the kernel - we can't have a different set for internal tasks.
Why? They are valid for all process (read and write), but their lifetimes are duplicates. |
edc184e to
38743af
Compare
73ffe2d to
f756035
Compare
Closes #6529
Closes #23012
Closes #31441
Closes #31629
Co-authored-by: @sigmaSd
Needs:
Deno's node:fs polyfills previously returned Deno Resource IDs (RIDs) from fs.open(), which are opaque internal indices. Node.js returns real OS file descriptors (integers like 3, 4, 5...), so code relying on fd semantics, including passing fds between worker threads — would break.
This PR implements a JavaScript-side FD-to-RID mapping layer:
About Cross-worker fd passing
When a worker receives an fd via postMessage():
This matches Node.js behavior where OS fds are process-wide.