Skip to content

Commit

Permalink
fixes #860: failure to exit on SIGINT race condition (#1157)
Browse files Browse the repository at this point in the history
* fixes #860: failure to exit on SIGINT race condition

* correct test name

* increase test timeout
  • Loading branch information
shellscape authored Oct 22, 2017
1 parent 3d72858 commit 0a8f896
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,9 @@ function startDevServer(webpackOptions, options) {

['SIGINT', 'SIGTERM'].forEach((sig) => {
process.on(sig, () => {
server.close();
process.exit(); // eslint-disable-line no-process-exit
server.close(() => {
process.exit(); // eslint-disable-line no-process-exit
});
});
});

Expand Down
23 changes: 20 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"eslint": "^4.5.0",
"eslint-config-webpack": "^1.2.5",
"eslint-plugin-import": "^2.7.0",
"execa": "^0.8.0",
"file-loader": "^0.11.2",
"istanbul": "^0.4.5",
"jquery": "^3.2.1",
Expand Down
28 changes: 28 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const assert = require('assert');
const path = require('path');
const execa = require('execa');

describe('SIGINT', () => {
it('should exit the process when SIGINT is detected', (done) => {
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
const examplePath = path.resolve(__dirname, '../examples/cli-public');
const nodePath = execa.shellSync('which node').stdout;

const proc = execa(nodePath, [cliPath], { cwd: examplePath });

proc.stdout.on('data', (data) => {
const bits = data.toString();

if (/webpack: Compiled successfully/.test(bits)) {
assert(proc.pid !== 0);
proc.kill('SIGINT');
}
});

proc.on('exit', () => {
done();
});
}).timeout(4000);
});

0 comments on commit 0a8f896

Please sign in to comment.