Skip to content

Commit 0a8f896

Browse files
authored
fixes #860: failure to exit on SIGINT race condition (#1157)
* fixes #860: failure to exit on SIGINT race condition * correct test name * increase test timeout
1 parent 3d72858 commit 0a8f896

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

bin/webpack-dev-server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ function startDevServer(webpackOptions, options) {
390390

391391
['SIGINT', 'SIGTERM'].forEach((sig) => {
392392
process.on(sig, () => {
393-
server.close();
394-
process.exit(); // eslint-disable-line no-process-exit
393+
server.close(() => {
394+
process.exit(); // eslint-disable-line no-process-exit
395+
});
395396
});
396397
});
397398

package-lock.json

Lines changed: 20 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"eslint": "^4.5.0",
7474
"eslint-config-webpack": "^1.2.5",
7575
"eslint-plugin-import": "^2.7.0",
76+
"execa": "^0.8.0",
7677
"file-loader": "^0.11.2",
7778
"istanbul": "^0.4.5",
7879
"jquery": "^3.2.1",

test/cli.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const path = require('path');
5+
const execa = require('execa');
6+
7+
describe('SIGINT', () => {
8+
it('should exit the process when SIGINT is detected', (done) => {
9+
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
10+
const examplePath = path.resolve(__dirname, '../examples/cli-public');
11+
const nodePath = execa.shellSync('which node').stdout;
12+
13+
const proc = execa(nodePath, [cliPath], { cwd: examplePath });
14+
15+
proc.stdout.on('data', (data) => {
16+
const bits = data.toString();
17+
18+
if (/webpack: Compiled successfully/.test(bits)) {
19+
assert(proc.pid !== 0);
20+
proc.kill('SIGINT');
21+
}
22+
});
23+
24+
proc.on('exit', () => {
25+
done();
26+
});
27+
}).timeout(4000);
28+
});

0 commit comments

Comments
 (0)