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

Raise a warning when listening for usafe signals #8601

Closed
wants to merge 1 commit into from

Conversation

quibusus
Copy link

Checklist
Description of change

We might want to emit a warning for signals that users shouldn’t listen on (as listed in the docs warning in #8410)

@nodejs-github-bot nodejs-github-bot added the process Issues and PRs related to the process subsystem. label Sep 17, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Sep 17, 2016

I don't think this is something we necessarily need to be doing.

@MylesBorins
Copy link
Contributor

We need to be very careful about adding extra warnings, they have proven to be unexpectadly fragile in the past

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

Like the idea, impl could use some tweaks


});


Copy link
Contributor

Choose a reason for hiding this comment

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

remove all but one newline here please

@@ -0,0 +1,12 @@
'use strict';
require('../common');
var assert = require('assert');
Copy link
Contributor

Choose a reason for hiding this comment

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

const

require('../common');
var assert = require('assert');

process.on('warning', function(warning) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please wrap the warning listeners in common.mustCall() in both tests.

@@ -191,6 +191,11 @@ function setupSignalHandlers() {
process.on('newListener', function(type, listener) {
if (isSignal(type) &&
!signalWraps.hasOwnProperty(type)) {

if (['SIGBUS', 'SIGFPE', 'SIGSEGV', 'SIGILL'].includes(type)) {
process.emitWarning('SIGBUS, SIGFPE, SIGSEGV and SIGILL are not safe');
Copy link
Contributor

@Fishrock123 Fishrock123 Sep 17, 2016

Choose a reason for hiding this comment

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

The message could probably be a bit more descriptive.

e.g.

Listening to X, X, etc signals are not safe and the listener may be called in an infinite loop

or something

@addaleax
Copy link
Member

We need to be very careful about adding extra warnings, they have proven to be unexpectadly fragile in the past

I’d be pretty okay with this not ending up in v6 or v7. People who are using non-up-to-date versions of signal-exit (6M downloads/month) would get a warning, so giving it a bit of time would probably be nice. (I’m adding the labels but if people’s opinions differ they may feel free to remove it).

Getting told that listening on SIGSEGV is not safe may be a huge debugging help when the problems actually arise, though.

@quibusus quibusus changed the title Raise a warning when listening for usafe signals #8591 Raise a warning when listening for usafe signals Sep 18, 2016
@quibusus
Copy link
Author

Thank you guys for the feedback, changes are ready for review

@@ -191,6 +191,14 @@ function setupSignalHandlers() {
process.on('newListener', function(type, listener) {
if (isSignal(type) &&
!signalWraps.hasOwnProperty(type)) {

if (['SIGBUS', 'SIGFPE', 'SIGSEGV', 'SIGILL'].includes(type)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be faster to use a Map or something similar here.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, indexOf is 5-10x faster in this case


}, 0));

process.on('SIGINT', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please write as process.on('SIGINT', () => {});

'use strict';
const common = require('../common');

process.on('warning', common.mustCall((warning) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

process.on('warning', common.fail);

'loop');
}, 1));

process.on('SIGBUS', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment regarding whitespace/formatting here.

'Listening to SIGBUS, SIGFPE, SIGSEGV, SIGILL signals ' +
'is not safe and the listener may be called in an infinite ' +
'loop');
}, 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the , 1

const assert = require('assert');

process.on('warning', common.mustCall((warning) => {
assert.equal(warning.name, 'Warning');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use assert.strictEqual().

@bnoordhuis
Copy link
Member

Is this actually an issue? If people want to listen for those signals, they presumably have their reasons. If we're printing warnings like this we should rename the project to Nanny.js.

@addaleax
Copy link
Member

Is this actually an issue? If people want to listen for those signals, they presumably have their reasons.

I don’t know if you count that as “actually an issue”, but yes, signal-exit did that in the past, and an application using it would just hang when receiving a SIGSEGV (which actually occurred with npm). I’m not sure what other modules do that, but I wouldn’t want to remote-debug something like that again, because it’s really unclear what the underlying problem is when looking at the symptoms.

@quibusus
Copy link
Author

I think this is a good to have feature. It will make using node safer with very little overhead.

@Fishrock123
Copy link
Contributor

So, this only effects on listeners and not once listeners, right?

Is there a way to differentiate?

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Sep 20, 2016
@jasnell
Copy link
Member

jasnell commented Sep 20, 2016

Given the increased possibility of breaking things that adding warnings has had in the past, I'm marking this as semver-minor. It would likely be good to have a citgm run on this just in case.

@addaleax
Copy link
Member

@quibusus Sorry, this seems to have merge conflicts… could you rebase this against master?

@quibusus
Copy link
Author

@Fishrock123 - all changes are done
@addaleax - rebased onto nodejs/node/master

how about the once listeners mentioned by @Fishrock123 ? should this be covered too ?

@vkurchatkin
Copy link
Contributor

-1, either this should be a proper deprecation or no warning at all. There are a lot of potentially unsafe things that we don't warn about, I don't think that we should start

@Fishrock123
Copy link
Contributor

If I understand correctly, this is safe if you use EventEmitter#once? I don't think there is a good way to detect that unfortunately.

@addaleax
Copy link
Member

If I understand correctly, this is safe if you use EventEmitter#once? I don't think there is a good way to detect that unfortunately.

It isn’t, and the current code does warn when #once is being used, too.

@rvagg rvagg force-pushed the master branch 2 times, most recently from c133999 to 83c7a88 Compare October 18, 2016 17:02
@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 1, 2017
@jasnell
Copy link
Member

jasnell commented Aug 24, 2017

Closing due to lack of forward progress. We can reopen if necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. semver-minor PRs that contain new features and should be released in the next minor version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants