Skip to content
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

Improve ChildProcess::killed property behaviour. Or update documentation. #16747

Closed
eduardbme opened this issue Nov 4, 2017 · 4 comments
Closed
Labels
child_process Issues and PRs related to the child_process subsystem.

Comments

@eduardbme
Copy link
Contributor

eduardbme commented Nov 4, 2017

  • Subsystem: doc and child_process

According to documentation (https://nodejs.org/dist/latest-v9.x/docs/api/child_process.html#child_process_subprocess_killed) the killed property has invalid semantic in comparison to ChildProcess::kill method behaviour (internal/child_process.js)

Concretely, the problematic code is

var err = this._handle.kill(signal);
if (err === 0) {
  /* Success. */
  this.killed = true;
  return true;
}

After the this._handle.kill(signal); method call we have no idea whether the 3-d party process was killed, or it just received a signal, processed it and continues working (it maybe be possible even with such 'kill' signals like SIGINT and SIGTERM).

So I propose to discuss what can be done in this direction to improve expected behaviour.

The easiest solution (and maybe the right one) is to move this.killed = true; line into _handle.onexit function and fix to the following code:

if (signalCode) {
  this.signalCode = signalCode;
  if (this._killWasCalled) { (1)
    this.killed = true;
  }
} else {
  this.exitCode = exitCode;
}

The if block (1) is needed cuz now documentation says '...indicates whether the child process was successfully terminated using subprocess.kill()'. We can eliminate this block, but we will need to update documentation also.

Strictly speaking, the killed field isn't very helpful in terms of identifying when process will exit.
We usually use exitevent for that. But, nevertheless, it's strange to see childProcess.killed === true, when in reality process works fine.

@cjihrig
Copy link
Contributor

cjihrig commented Nov 4, 2017

My take on this is that it is a documentation issue: #16748

@eduardbme
Copy link
Contributor Author

@cjihrig

why not update code ?

kill/killed is historically bad name for just signal notification, but we do not have to follow this rule.

Moreover, the killed param that indicates just correct signal notification isn't very helpful cuz the kill method already returns true for that purpose. Logic duplication and no advantage to use killed param at all.

@cjihrig
Copy link
Contributor

cjihrig commented Nov 4, 2017

why not update code ?

Updating the code is much more likely to break existing applications in non-obvious ways. The 'exit' event also provides the signal used to terminate the process, so you can check that.

kill/killed is historically bad name for just signal notification, but we do not have to follow this rule.

I'm not saying it's a great name, but this flag is literally indicating the result of calling kill(2) (on non-Windows platforms).

@mscdex mscdex added the child_process Issues and PRs related to the child_process subsystem. label Nov 4, 2017
@eduardbme
Copy link
Contributor Author

What if we will deprecate this property in the next versions ?

I do not see any advantage to use it in that form. That's rudimental functionality.

cjihrig added a commit to cjihrig/node that referenced this issue Nov 7, 2017
This commit changes the wording of subprocess.killed to reflect
that a child process was successfully signaled, and not
necessarily terminated.

Fixes: nodejs#16747
PR-URL: nodejs#16748
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this issue Nov 13, 2017
This commit changes the wording of subprocess.killed to reflect
that a child process was successfully signaled, and not
necessarily terminated.

Fixes: #16747
PR-URL: #16748
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 17, 2017
This commit changes the wording of subprocess.killed to reflect
that a child process was successfully signaled, and not
necessarily terminated.

Fixes: #16747
PR-URL: #16748
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 17, 2017
This commit changes the wording of subprocess.killed to reflect
that a child process was successfully signaled, and not
necessarily terminated.

Fixes: #16747
PR-URL: #16748
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 21, 2017
This commit changes the wording of subprocess.killed to reflect
that a child process was successfully signaled, and not
necessarily terminated.

Fixes: #16747
PR-URL: #16748
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 28, 2017
This commit changes the wording of subprocess.killed to reflect
that a child process was successfully signaled, and not
necessarily terminated.

Fixes: #16747
PR-URL: #16748
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants