nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.58k stars 29.06k forks source link

child_process: ERR_INVALID_ARG_TYPE on .kill() #30702

Open paul-marechal opened 4 years ago

paul-marechal commented 4 years ago

We are getting the following stack trace when killing a child_process:

root ERROR TypeError [ERR_INVALID_ARG_TYPE]: The "err" argument must be of type number. Received type undefined
    at validateNumber (internal/validators.js:130:11)
    at Object.getSystemErrorName (util.js:1435:3)
    at errnoException (internal/errors.js:303:21)
    at ChildProcess.kill (internal/child_process.js:430:26)

From what I can make of it, it seems to be caused by the following code:

https://github.com/nodejs/node/blob/v10.x/lib/internal/child_process.js#L425-L439

    var err = this._handle.kill(signal);
    if (err === 0) {
      /* Success. */
      this.killed = true;
      return true;
    }
    if (err === UV_ESRCH) {
      /* Already dead. */
    } else if (err === UV_EINVAL || err === UV_ENOSYS) {
      /* The underlying platform doesn't support this signal. */
      throw errnoException(err, 'kill');
    } else {
      /* Other error, almost certainly EPERM. */
      this.emit('error', errnoException(err, 'kill'));
    }

Somehow, err seems to be undefined, making us land in the last else branch, but then errnoException doesn't know what to make out of it and throws the error that we see.

The issue only happens in Electron, so it might not be entirely related to Node, but I was wondering if this err value is expected to be undefined in some circumstance?

nicholaswmin commented 1 month ago

I get this issue when I'm trying to kill a childProcess that has already exited

RedYetiDev commented 3 days ago

I get this issue when I'm trying to kill a childProcess that has already exited

Can you provide a minimal reproduction?

nicholaswmin commented 3 days ago

Going to be exceptionally hard but ill try. Ive spent a month on a child process module I need for work and have only seen it 5-6 times.

At the time of posting this I could reliably repro otherwise I wouldnt have posted this, sadly ddnt get a repro them.

Ill give it another go tomrrow for a while, if I get it ill post one, doubt it though.

Also im on MacOS Sonoma, Node v22.3 - OP is Win