Skip to content

Commit ceb5331

Browse files
committed
Force exit on SIGINT but still reset flags on stdio fds
Add test that one can ctrl+c out of a script spinning infinitely.
1 parent 33e45bb commit ceb5331

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/node.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,8 @@ static void AtExit() {
17761776

17771777

17781778
static void SignalExit(int signal) {
1779-
ev_unloop(EV_DEFAULT_ EVUNLOOP_ALL);
1779+
AtExit();
1780+
exit(1);
17801781
}
17811782

17821783

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This test is to assert that we can SIGINT a script which loops forever.
2+
// ref: http://groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f
3+
var common = require('../common');
4+
var assert = require('assert');
5+
var spawn = require('child_process').spawn;
6+
7+
console.log("start");
8+
9+
var c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']);
10+
11+
var sentKill = false;
12+
var gotChildExit = true;
13+
14+
c.stdout.on('data', function (s) {
15+
// Prevent race condition:
16+
// Wait for the first bit of output from the child process
17+
// so that we're sure that it's in the V8 event loop and not
18+
// just in the startup phase of execution.
19+
if (!sentKill) {
20+
c.kill('SIGINT')
21+
console.log("SIGINT infinite-loop.js");
22+
sentKill = true;
23+
}
24+
});
25+
26+
c.on('exit', function (code) {
27+
assert.ok(code !== 0);
28+
console.log("killed infinite-loop.js");
29+
gotChildExit = true;
30+
});
31+
32+
process.on('exit', function () {
33+
assert.ok(sentKill);
34+
assert.ok(gotChildExit);
35+
});
36+

0 commit comments

Comments
 (0)