Skip to content

Loading…

Show error message of Signal Events unsupported on Windows #2904

Closed
wants to merge 2 commits into from

5 participants

@shigeki

As discussed #1553, signal events are not yet supported on Windows.
The current error message of

process.on('SIGINT', function() {});

is shown on Windows as

C:\Users\ohtsu\Desktop\node\node>Release\node.exe test.js

node.js:197
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: No such module
    at EventEmitter.<anonymous> (node.js:388:27)
    at Object.<anonymous> (C:\Users\ohtsu\Desktop\node\node\test.js:1:71)
    at Module._compile (module.js:443:26)
    at Object..js (module.js:461:10)
    at Module.load (module.js:350:32)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:481:10)
    at EventEmitter._tickCallback (node.js:188:41)

The error description of "No such module" is too ambiguous for users.
This patch shows it more clearly as

C:\Users\ohtsu\Desktop\shigeki>Release\node.exe test.js

node.js:197
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Signal Event: SIGINT is not yet supported on Windows.
    at EventEmitter.<anonymous> (node.js:388:17)
    at Object.<anonymous> (C:\Users\ohtsu\Desktop\shigeki\test.js:1:71)
    at Module._compile (module.js:443:26)
    at Object..js (module.js:461:10)
    at Module.load (module.js:350:32)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:481:10)
    at EventEmitter._tickCallback (node.js:188:41)

I also add notes on doc that signal events are not yet supported on Windows.

@Southern Southern commented on an outdated diff
doc/api/process.markdown
@@ -55,6 +55,7 @@ stay running forever, `uncaughtException` can be a useful safety mechanism.
Emitted when the processes receives a signal. See sigaction(2) for a list of
standard POSIX signal names such as SIGINT, SIGUSR1, etc.
+Signal Events are not yet supported on Windows.

Should probably bold it to grab more attention. Had to put a couple of notes like this in readline's docs.

@shigeki
shigeki added a note

Thanks for the comment. I change the doc description into the same as that in readline. I think that there's no actual workaround on this for simulating this with key events through stdin depends on the key assignments by user, so I did not add the additional notes on it.

If your program uses readline, you can always bind to readline.on('SIGINT', ...). Readline picks up ^C through stdin keypresses.

@shigeki
shigeki added a note

I'm using the keypress event of Ctrl-c in stdin direcly. I agree that readline is the alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@domenic
Node.js Foundation member

+1, I believe this cryptic error message is what is preventing me from running the npm-www site on Windows.

@domenic domenic referenced this pull request in isaacs/cluster-master
Closed

Wrap SIGHUP/SIGINT/SIGKILL listening in try/catch #1

@isaacs isaacs added a commit to isaacs/cluster-master that referenced this pull request
@domenic domenic Wrap SIGHUP/SIGINT/SIGKILL listening in try/catch
Now the module can at least bootstrap itself without crashing on Windows.

Related: nodejs/node-v0.x-archive#2904
3b8a0ab
@Nodejs-Jenkins

Can one of the admins verify this patch?

@domenic
Node.js Foundation member

Was this fixed with a test?

@chrisdickinson

@domenic This was closed because node supports SIGINT & SIGHUP, as tested locally on windows xp with node v0.10.30. The docs also reflect this change as of 155df9c. All platforms throw an error when listening for SIGKILL. I did not track down the changeset that changed the behavior on Windows, though -- I can if you'd like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 20 additions and 6 deletions.
  1. +2 −0 doc/api/process.markdown
  2. +4 −0 src/node.js
  3. +14 −6 test/simple/test-signal-handler.js
View
2 doc/api/process.markdown
@@ -53,6 +53,8 @@ stay running forever, `uncaughtException` can be a useful safety mechanism.
<!--type=event-->
<!--name=SIGINT, SIGUSR1, etc.-->
+**This does not work on Windows.**
+
Emitted when the processes receives a signal. See sigaction(2) for a list of
standard POSIX signal names such as SIGINT, SIGUSR1, etc.
View
4 src/node.js
@@ -384,6 +384,10 @@
process.on = process.addListener = function(type, listener) {
var ret = addListener.apply(this, arguments);
if (isSignal(type)) {
+ if (process.platform === 'win32') {
+ throw new Error('Signal Event: ' + type + ' is not yet supported on Windows.');
+ }
+
if (!signalWatchers.hasOwnProperty(type)) {
var b = process.binding('signal_watcher');
var w = new b.SignalWatcher(startup.lazyConstants()[type]);
View
20 test/simple/test-signal-handler.js
@@ -18,18 +18,26 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
+var common = require('../common');
+var assert = require('assert');
+console.log('process.pid: ' + process.pid);
-// SIGUSR1 and SIGHUP are not supported on Windows
+// SIGINT is not yet supported on Windows.
if (process.platform === 'win32') {
+ var errmsg = 'Signal Event: SIGINT is not yet supported on Windows.';
+ assert.throws(function() {
+ process.on('SIGINT', function() {});
+ }, function(err) {
+ if (err instanceof Error) {
+ assert.strictEqual(err.message, errmsg);
+ return true;
+ }
+ });
+ // Rest of tests are not supported on Windows.
process.exit(0);
}
-var common = require('../common');
-var assert = require('assert');
-
-console.log('process.pid: ' + process.pid);
-
var first = 0,
second = 0;
Something went wrong with that request. Please try again.