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

Child process remains alive after parent terminates while being debugged #13538

Closed
dead-claudia opened this issue Jun 8, 2017 · 7 comments
Closed
Labels
child_process Issues and PRs related to the child_process subsystem. inspector Issues and PRs related to the V8 inspector protocol

Comments

@dead-claudia
Copy link

dead-claudia commented Jun 8, 2017

  • Version: 8.0.0
  • Platform: macOS Sierra
  • Subsystem: child_process

Steps:

  1. Type the following code below into a module.
  2. Run it in a terminal with no arguments.
  3. Attach Chrome's Devtools debugger to the child process.
  4. Kill the parent.
if (process.execArgv.includes("--inspect-brk") return
child_process.spawn(process.argv[0], [__filename, "--inspect-brk"], {
  stdio: "inherit",
})
.on("exit", () => { console.log("exit") })
.on("error", () => { console.log("error") })

Expected:

The child should've been killed along with the parent, with the debugger disconnected.

Observed:

The child remains alive with the debugger at the first line waiting.

@dead-claudia
Copy link
Author

Yes, the script recursively calls itself, but that's irrelevant to the repro (it's just easier to write/use).

@dead-claudia
Copy link
Author

Also, it may be the underlying cause of #10158 and friends.

@mscdex mscdex added child_process Issues and PRs related to the child_process subsystem. inspector Issues and PRs related to the V8 inspector protocol labels Jun 8, 2017
@dead-claudia
Copy link
Author

My current workaround is using process.on("exit", () => child.kill()).

@dead-claudia dead-claudia changed the title Child process remains alive after parent exits while being debugged Child process remains alive after parent terminates while being debugged Jun 8, 2017
@bnoordhuis
Copy link
Member

The child should've been killed along with the parent, with the debugger disconnected.

Why would you expect that? Node doesn't kill child processes when the parent process exits, debugger or no debugger. (The kernel does on ^C but that's a different mechanism.)

@dead-claudia
Copy link
Author

dead-claudia commented Jun 9, 2017

@bnoordhuis

Why would you expect that? Node doesn't kill child processes when the parent process exits, debugger or no debugger. (The kernel does on ^C but that's a different mechanism.)

I edited the original bug to clarify killing the parent is what I meant. (I know ^C does that iff there are no SIGTERM handlers attached, so I removed that particular instruction.)

But here's the behavior I'm expecting:

  1. A SIGTERM is sent to the parent.
  2. The default action of termination + sending a SIGHUP to the child is performed.
  3. No handler is registered for SIGHUP. (i.e. no process.on("SIGHUP", () => { ... }))
  4. The default action of termination is performed.

The issue is likely that of the SIGHUP handler being registered and not killing the process upon reception.

@bnoordhuis
Copy link
Member

Still sounds like the wrong expectation to me. When SIGTERM terminates the parent, children get reparented to the grandparent. That's not node-specific, it's traditional UNIX behavior.

You mention SIGHUP but that is normally only sent when the controlling tty goes away (nominally, when the user logs out.) Again, not node-specific.

@dead-claudia
Copy link
Author

children get reparented to the grandparent

I competely missed that part (which really changes my expectations here). So I'll go ahead and close this.

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. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

No branches or pull requests

3 participants