-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Parent-child pipes not relayed #613
Comments
This happens because tsx also spawns a node process and isn't relaying the pipes it receives from the parent process: Lines 15 to 19 in 2688300
Do you know if there's a good way to detect all the pipes attached to the current process by the parent? Not a lot of info in the docs: https://nodejs.org/api/child_process.html#optionsstdio As far as I understand, the only way is to do something like: import fs from 'fs';
const stdio = [];
for (let fd = 0; fd < 100; fd++) { // Arbitrary upper limit for file descriptors
try {
fs.fstatSync(fd); // If this doesn't throw, fd is valid
stdio.push('inherit');
} catch (err) {
if (err.code !== 'EBADF') { // EBADF means fd is not valid
throw err;
}
}
} But I prefer we're not doing an arbitrary number of stat and try-catches on startup. |
Hi, thanks for the quick feedback ! There are platform specific ways, e.g. Linux (or unix like MacOS) have /proc/fd which lists open files and I believe it would be quite efficient to scan that on startup. There must be a windows API for that also, but not necessarily available from node. But at this point it's probably more trouble than it's worth. I don't see a standard, cross-platform way of doing it, apart from what you propose, which does not seem very nice. Also, just adding a bunch of "inherit" to stdio options just in case is not a good option either because it changes the error code when trying to open a file descriptor which could also break some edge cases. I guess one option would be to have a way to configure this through command line parameters or otherwise, but I understand one of the point of this project is to "just work" with no configuration, so I don't know if that fits. Also if you look at the broader picture, there are many IPC mechanisms ; detecting and forwarding them all seems unrealistic. So maybe the easier resolution is to accept that this use-case is not handled by tsx, but it should be documented. In the meantime I'm gonna try my luck with |
Acknowledgements
Minimal reproduction URL
https://stackblitz.com/edit/node-qzmjn4?file=main.js
Problem & expected behavior (under 200 words)
I'm not aware of how
tsx
works internally, but apparently it breaks at least some forms of inter-process communication. I setup a child process to have a stream (fd 3) to talk with it's parent, but that becomes unusable when using tsx. Spent quite a bit of time to track the issue to tsx actually ^_^I don't know if this is easily fixable, but at least it should be documented somewhere.
Bugs are expected to be fixed by those affected by it
Compensating engineering work will speed up resolution and support the project
The text was updated successfully, but these errors were encountered: