-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack-dev-server
cannot be killed when spawned with child_process
#2168
Comments
webpack-dev-server
is orphaned instead of killed when spawned with child_process
webpack-dev-server
cannot be killed when spawned with child_process
I think duplicate #1479, we can't kill process when webpack do compilation right now, also it is unsafe for cache |
Here explain #1479 (comment) |
If I comment out the |
@AaronBeaudoin try to use |
If the point is to ensure that compiling has completed before trying to kill the process then it's irrelevant. I get the |
Also it seems that using the const { fork: forkProcess } = require("child_process");
let devServerProcess = forkProcess(
".\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js", []);
setTimeout(_ => {
devServerProcess.kill();
console.log("Trying to kill webpack-dev-server...");
}, 5000); |
@AaronBeaudoin thanks for investigation, we look on this in near future, anyway feel free to debug and send a PR with fix |
In case it helps, it seems that when spawning processes with |
@AaronBeaudoin maybe it is only on windows, can you sty this on linux? |
Is there a solution? |
@evilebottnawi |
@xiaoyouyu better use setTimeout(() => {
subprocess.kill('SIGTERM', {
forceKillAfterTimeout: 2000
});
}, 1000); |
In my case I've solved same issue by next steps: Firstly added Windows-specific code to emit const rl = require('readline');
if (/^win/.test(process.platform)) {
rl.createInterface({
input: process.stdin,
output: process.stdout
}).on('SIGINT', () => process.emit('SIGINT'));
} Secondly added specific code to kill process on different OS. const { execSync } = require('child_process');
function killChildProcess(childProcess) {
if (/^win/.test(process.platform)) {
execSync(`taskkill /pid ${childProcess.pid} /f /t`);
} else {
process.kill(childProcess.pid);
}
}; |
How to get the |
@ifedyukin 干的漂亮
|
@xiaoyouyu I started WDS using |
/cc @hiroppy we have same problems with webpack-cli, investigate |
I found a description for an option with this document #devserverstdin---cli-only. webpack-dev-server/lib/utils/createConfig.js Lines 83 to 90 in c9e9178
But in options.json I can't found the schema with stdin .I add the stdin schema in the options.json .ummmm,Seems to work…… But why?The documents tall me, you can use it. But the fact is that it cannot be used. This confused me. 🤔 |
@Jfreey please tell the version of |
@snitin315 Please check This is the {
"name": "dev_server_stdin_bug",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
}
} I add the property to "stdin":{
"type": "boolean"
}, The code is below this line: webpack-dev-server/lib/options.json Lines 362 to 381 in 4ab1f21
Well then, It can work... |
I think we can close it - no activity, if you faced with this problem again feel free to open a new issue |
@AaronBeaudoin were u able to solve this? When running wds through child_process.spawn(), im able to reproduce: this message just hangs But when I run wds through command line ie. |
Having the same issue (on MacOS). const appProcess = spawn("npm", ["run", "serve"]); // runs "webpack serve"
...
appProcess.kill(); // returns true, but "webpack" still running |
@matthiasgeihs Can you open a new issue with the reproducible example, thank you |
@alexander-akait created #5026 |
Expected Behavior
webpack-dev-server
should be killed withchildProcess.kill()
after spawning it withrequire("child_process").spawn()
.Actual Behavior
webpack-dev-server
is orphaned instead of being killed in the above scenario.Steps to Reproduce
Create a folder with the following
package.json
:Add a
test.js
file:Add a
src.js
file to satisfy thewebpack
zero-config defaults:Run
npm i
thennode test.js
and check the running processes on your system. Thewebpack-dev-server
node has not been killed as expected.Note
This issue still occurs when the
stdio
option is not supplied to thespawn
function.The text was updated successfully, but these errors were encountered: