Skip to content

Commit ecd5244

Browse files
committed
Raise a warning when listening for usafe signals #8601
1 parent 7f71419 commit ecd5244

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/internal/process.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ function setupSignalHandlers() {
191191
process.on('newListener', function(type, listener) {
192192
if (isSignal(type) &&
193193
!signalWraps.hasOwnProperty(type)) {
194+
195+
if (['SIGBUS', 'SIGFPE', 'SIGSEGV', 'SIGILL'].indexOf(type) > -1) {
196+
process.emitWarning(
197+
'Listening to SIGBUS, SIGFPE, SIGSEGV, SIGILL signals ' +
198+
'is not safe and the listener may be called in an ' +
199+
'infinite loop');
200+
}
201+
194202
const Signal = process.binding('signal_wrap').Signal;
195203
const wrap = new Signal();
196204

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
process.on('warning', common.fail);
5+
process.on('SIGINT', () => {});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
process.on('warning', common.mustCall((warning) => {
6+
assert.strictEqual(warning.name, 'Warning');
7+
assert.strictEqual(warning.message,
8+
'Listening to SIGBUS, SIGFPE, SIGSEGV, SIGILL signals ' +
9+
'is not safe and the listener may be called in an ' +
10+
'infinite loop');
11+
}));
12+
13+
process.on('SIGBUS', () => {});

0 commit comments

Comments
 (0)