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

doc: note that listening on SIGSEGV & co is unsafe #8410

Closed
wants to merge 3 commits into from

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Sep 5, 2016

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

Description of change

Note that trying to listen for some signals using process.on() is unsafe in the process docs.

Note that trying to listen for some signals using `process.on()`
is unsafe in the `process` docs.
@addaleax addaleax added doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem. labels Sep 5, 2016
addaleax added a commit to addaleax/signal-exit that referenced this pull request Sep 5, 2016
Listening for one of these signals from JS will make the process
enter an infinite loop when encountering them naturally
because the underlying problem is not resolved while the signal
handler is being scheduled.

Ref: npm/npm#13782
Ref: nodejs/node#8410
@bnoordhuis
Copy link
Member

LGTM

@@ -422,6 +422,9 @@ It is important to take note of the following:
* `SIGKILL` cannot have a listener installed, it will unconditionally terminate
Node.js on all platforms.
* `SIGSTOP` cannot have a listener installed.
* `SIGBUS`, `SIGFPE`, `SIGSEGV` and `SIGILL`, when not raised artificially,
inherently leave the process in a state from which it is not safe to
attempt to call JS listeners.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does core not call listeners then...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libuv schedules them to run, but the control flow returns from the signal handler before actually calling anything. As far as I have been able to tell, that means that the offending code will just be executed again, triggering the signal again, etc. in an infinite loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 sorry, occurs to me that I might have misread your question – node does try to call the listeners in the usual way, and that works perfectly when the signal is artificially generated, as in process.kill(process.pid, 'SIGSEGV').

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and that works perfectly when the signal is artificially generated,

Does that imply that we should not allow these signals to trigger when they are not artificial?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that imply that we should not allow these signals to trigger when they are not artificial?

We might be able to do that… libuv would need to set SA_SIGINFO, which comes with this warning in the Linux manpage:

Use of these latter values in sa_flags may be less portable in applications intended for older UNIX implementations.

I am not sure what practical use cases for manually triggering SIGSEGV there are, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax I mean, should these listeners even function if it is not safe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 I would say no, but it’s probably not something worth the trouble of removing…

@cjihrig
Copy link
Contributor

cjihrig commented Sep 5, 2016

LGTM

@@ -422,6 +422,9 @@ It is important to take note of the following:
* `SIGKILL` cannot have a listener installed, it will unconditionally terminate
Node.js on all platforms.
* `SIGSTOP` cannot have a listener installed.
* `SIGBUS`, `SIGFPE`, `SIGSEGV` and `SIGILL`, when not raised artificially,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raised artificially is a bit obscure. I'm not sure the average reader will know that that means.

@jasnell
Copy link
Member

jasnell commented Sep 7, 2016

While this is ok in general, I think it would be beneficial to describe the risk a bit more.

@bnoordhuis
Copy link
Member

It seems fine to me as is, really. You could s/raised artificially/sent explicitly/ but that's not even much of an improvement, IMO.

@addaleax
Copy link
Member Author

addaleax commented Sep 8, 2016

I’ve added a bit more explanation on what might happen and a reference to the kill(2) manpage, hopefully that clears things up a bit… idk, the language around signals is usually based on raise as a verb.

bcoe pushed a commit to tapjs/signal-exit that referenced this pull request Sep 8, 2016
Listening for one of these signals from JS will make the process
enter an infinite loop when encountering them naturally
because the underlying problem is not resolved while the signal
handler is being scheduled.

Ref: npm/npm#13782
Ref: nodejs/node#8410
@Fishrock123
Copy link
Contributor

seems fine to me then

@jasnell
Copy link
Member

jasnell commented Sep 8, 2016

LGTM. I appreciate the tweaks.

@cjihrig
Copy link
Contributor

cjihrig commented Sep 9, 2016

LGTM

jasnell pushed a commit that referenced this pull request Sep 12, 2016
Note that trying to listen for some signals using `process.on()`
is unsafe in the `process` docs.

PR-URL: #8410
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Member

jasnell commented Sep 12, 2016

Landed in 3207ea4

@jasnell jasnell closed this Sep 12, 2016
Fishrock123 pushed a commit that referenced this pull request Sep 14, 2016
Note that trying to listen for some signals using `process.on()`
is unsafe in the `process` docs.

PR-URL: #8410
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax addaleax deleted the doc-process-signals branch January 28, 2019 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants