-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Conversation
I don't think this is something we necessarily need to be doing. |
We need to be very careful about adding extra warnings, they have proven to be unexpectadly fragile in the past |
There was a problem hiding this 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
|
||
}); | ||
|
||
|
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
lib/internal/process.js
Outdated
@@ -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'); |
There was a problem hiding this comment.
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
I’d be pretty okay with this not ending up in v6 or v7. People who are using non-up-to-date versions of Getting told that listening on |
9654c2a
to
4544667
Compare
Thank you guys for the feedback, changes are ready for review |
lib/internal/process.js
Outdated
@@ -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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use assert.strictEqual()
.
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. |
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. |
I think this is a good to have feature. It will make using node safer with very little overhead. |
So, this only effects Is there a way to differentiate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. |
@quibusus Sorry, this seems to have merge conflicts… could you rebase this against |
@Fishrock123 - all changes are done how about the |
-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 |
If I understand correctly, this is safe if you use |
It isn’t, and the current code does warn when |
c133999
to
83c7a88
Compare
Closing due to lack of forward progress. We can reopen if necessary |
Checklist
make -j4 test
(UNIX)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)