Validity of file descriptors in the context of the SyncKit
worker
#400
Labels
target-deno
This is about the Deno target
Milestone
While debugging the
jco
preview2-shim unit tests underdeno
I stumbled over another grave compatibility issue. It's more or less hidden when executed onnodejs
, but has its roots in an undeniable design flaw ofjco
:It breaks the test case "FS read" in a rather drastic way, when used on
deno
, but isn't easy to grasp on first sight.It's caused by the fact, that
jco
handles some filesystem related tasks (opening of files in particular) within the context of the main instance, while most other io-related operations (reading files etc.) are happening within the context of aworker
thread used forSyncKit
s indirection.This unmediated transfer and use of open file descriptors on both sides works in
nodejs
andbun
at least somehow (well -- even there it's confusing the garbage collector and causing subtle troubles), but not ondeno
and it's much more secure/restrictive/efficient multi threading implementation.The problem isn't caused by the fact, that files descriptors are used for the communication between both realms -- no, they are just simple numbers --, but the file related operations, which they belong to, have to happen always in the same context, otherwise they become silently invalid!
You shouldn't open the files on one side and expect, that their file descriptor values are valid in other contexts as well. You simply can read from such a received file descriptor number behind the wall, which divides both threads/subprocesses/etc.
Here is a very simple script to test and demonstrate this issue:
While it will somehow work on
node
andbun
it will immediately reportERROR: BadResource: Bad resource ID
if you try to execute it viadeno run -A ./cross_realm_fd_reuse.mjs
.IMHO it's a really significant defect on
jco
s side, which should be carefully fixed to archive a more reliable and compatible code base. You just have to handle all file related operations in the same execution context resp. in the same manner.The text was updated successfully, but these errors were encountered: