-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Child process breaks on command #55802
Comments
I simplified your reproduction to: import { exec } from 'node:child_process';
exec("nmap --open 127.0.0.1", console.log); And I can't reproduce:
|
Seems like a problem w/ your environment, would you mind to change that IP into an exposed one? Like google's or github's IP? I can't reproduce the issue as well. Also Refs: https://docs.libuv.org/en/v1.x/errors.html#c.UV_ECONNRESET |
It may likely be a problem with my code base. I am continuing to investigate. I can reproduce this 100% on both Debian 12 and Windows 10. I just discovered that the problem does not occur if the application is executed from systemd. |
This does seem to be a valid Node issue. I have updated the issue at the top with my more recent observations. |
That seems to be a |
@aduh95 I was likely not clear when I was speaking to timing. const connection = function (tls_socket) {
// where sockets are born, the connection event handler
// for the sake of this thread socket errors must be trapped here before other functions are called, otherwise the application will break
// when evers are trapped later, even if before the breaking action, it is too late
tls_socket.on("error", function (error) {
console.log(error);
});
const handler = function (data:Buffer) {
// reason about the data and make determinations about protocol management and response messages
// ...
const socket = this;
socket.on("error", function (error) {
// errors on the socket are trapped, and those errors will not terminate the application
// except in this case its too late, and the application still reports a socket error and breaks
// Its interesting because the breaking action, a child process, does not execute until much later due to human interaction
};
};
tls_socket.once("data", handler);
};
// servers listening for connections
server.on("connection", connection); // net.server
node.tls.server.createServer({
ca: "key hash",
cert: "key hash",
key: "key hash"
}, connection); // tls.server Looking at the code above:
I cannot further reason about the nature of that timing. I am also unclear why executing a child process would have anything to do with a network socket's read stream. I can only speculate, and this is a completely uninformed guess, that there is a stream collision between the read stream of the socket and the pipes of the child process. If so its unclear why altering the timing of error trapping would have any effect or why executing the application from a higher privilege, run as root from systemd, would have any effect. I will be happy to continue investigating, but I suspect I am approaching the limits of what evidence I can gather from user land. |
Here is the application demonstrating the issue on branch "servers": https://github.com/prettydiff/webserver/tree/servers
The error can be suppressed by uncommenting the following three lines and repeating the process above (except for npm install): https://github.com/prettydiff/webserver/blob/servers/lib/transmit/server.ts#L291-L293 The actual failure occurs from this line: https://github.com/prettydiff/webserver/blob/servers/lib/utilities/port_map.ts#L75 This logic guarantees the error will occur within 10 seconds of application start regardless of further action and no connections: https://github.com/prettydiff/webserver/blob/servers/lib/index.ts#L75-L79 |
Version
23.1.0
Platform
Subsystem
No response
What steps will reproduce the bug?
nmap --open 127.0.0.1
via instruction from any kind of network stream, such as WebSocket message or HTTP request.How often does it reproduce? Is there a required condition?
I can reproduce this 100% from command line in both Debian 12 and Windows 10. 0% from systemd.
What is the expected behavior? Why is that the expected behavior?
child_process exec calls a callback and child_process spawn calls event handlers in accordance with Node API definitions.
What do you see instead?
The application crashes fatally if the error event on the corresponding socket is not trapped immediately at first connection time before other instructions are executed. Assigning a handler to the socket's error event listener later is insufficient, for example assigning the handler from within the following code still results in crashes:
The actual error reported by the socket is:
The error is the direct result of a child process execution. The corresponding child process executes in response to instructions transmitted on the corresponding socket, but is otherwise not related or associated to the socket.
This following error is the fatal error messaging if the error is not immediately trapped on the corresponding socket.
The error messaging describes a socket failure, but it is not. It is a child process call only and only on the command specified.
Additional information
Some of the things I have tried:
echo hello
andps -a
. They work without issue./bin/sh
and/bin/bash
The text was updated successfully, but these errors were encountered: