Skip to content

Commit ba683e1

Browse files
committed
fix #192: tmp must not exit the process on its own
1 parent 05aba23 commit ba683e1

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

lib/tmp.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,8 @@ function _safely_install_sigint_listener() {
627627
// ignore
628628
}
629629
}
630-
try {
631-
// force the garbage collector even it is called again in the exit listener
632-
_garbageCollector();
633-
} finally {
634-
if (!!doExit) {
635-
process.exit(0);
636-
}
637-
}
630+
// force the garbage collector even it is called again in the exit listener
631+
_garbageCollector();
638632
});
639633
}
640634

test/issue121-test.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const
77
os = require('os'),
88
rimraf = require('rimraf'),
99
testCases = [
10-
{ signal: 'SIGINT', expectExists: false },
11-
{ signal: 'SIGTERM', expectExists: true }
10+
'SIGINT',
11+
'SIGTERM'
1212
];
1313

1414
// skip tests on win32
@@ -18,10 +18,10 @@ const tfunc = isWindows ? xit : it;
1818
describe('tmp', function () {
1919
describe('issue121 - clean up on terminating signals', function () {
2020
for (let tc of testCases) {
21-
tfunc('for signal ' + tc.signal, function (done) {
22-
// increase timeout so that the child process may fail
23-
this.timeout(20000);
24-
issue121Tests(tc.signal, tc.expectExists)(done);
21+
tfunc('for signal ' + tc, function (done) {
22+
// increase timeout so that the child process may terminate in time
23+
this.timeout(5000);
24+
issue121Tests(tc)(done);
2525
});
2626
}
2727
});
@@ -33,22 +33,8 @@ function issue121Tests(signal, expectExists) {
3333
if (err) return done(err);
3434
else if (stderr) return done(new Error(stderr));
3535

36-
try {
37-
if (expectExists) {
38-
assertions.assertExists(stdout);
39-
}
40-
else {
41-
assertions.assertDoesNotExist(stdout);
42-
}
43-
done();
44-
} catch (err) {
45-
done(err);
46-
} finally {
47-
// cleanup
48-
if (expectExists) {
49-
rimraf.sync(stdout);
50-
}
51-
}
36+
assertions.assertDoesNotExist(stdout);
37+
done();
5238
}, signal);
5339
};
5440
}

test/outband/issue121.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
const
55
tmp = require('../../lib/tmp');
66

7+
// install exit handler since tmp will no longer exit on its own
8+
process.on('SIGINT', function () {
9+
process.exit(0);
10+
});
11+
12+
process.on('SIGTERM', function () {
13+
process.exit(0);
14+
});
15+
716
// https://github.com/raszi/node-tmp/issues/121
817
module.exports = function () {
918

0 commit comments

Comments
 (0)