-
-
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
can't close webpack-dev-server --progress with Ctrl + C #1479
Comments
Oops, spoke too soon. It still reproduces on 3.1.6... |
Still an issue with |
Having the issue on Linux and Mac with webpack-dev-server |
Please create minimum reproducible test repo with steps |
@SebT I've also had this issue, specifically when using the Edit: Alright, I've created a branch that consistently reproduces this here. To reproduce:
At this point, the dev server gets stuck at
|
The error (in this case, at least) appears to occur when the dev server gets stuck compiling. FWIW, I'm using VSCode with the Reason/OCaml extension. Edit: Alright, this latest commit consistently causes webpack to freeze at Edit 2: After trying to replicate on a second machine, this seems to be a borked install as everything is working fine. |
One developer in our team is having the same issue (the rest of the team not). So it's hard to offer a reproducible test. |
If somebody can reproducible test please post how here, we can fix it asap |
The same happens for me on Linux (up-to-date ArchLinux). Also it drains 100% of one CPU core. |
Can confirm I'm still experiencing this at webpack-dev-server 3.1.10, macOS 10.13.6 cc @nfm confirm whether you're still experiencing this one? |
Yes, this is still happening for me if I try to Ctrl-C when actively compiling. I can successfully Ctrl-C when WDS is idle though. |
Please create minimum reproducible test repo |
@evilebottnawi here you go: https://github.com/danburzo/webpack-dev-server-repro |
@danburzo What os i need to reproduce? |
In my initial report, I was on macOS High Sierra (10.13.6) when this happened. I am currently on macOS Mojave (10.14.1) and it still reproduces. |
(Note that @nfm is experiencing this on Ubuntu so it's not just macOS) |
@danburzo Awesome, reproduce problem on |
One interesting thing - it is happens when you try to |
Problem found, we use What we need to fix all problem with
If somebody have time to help with this issue PRs welcome |
Yes, we need watch these files, because you can add them late... But they should be closed very quickly |
The slowness is coming from this line https://github.com/webpack/watchpack/blob/master/lib/watchEventSource.js#L75 where the NodeJS FSWatcher is closed. In my case, I count 1219 executions of FSWatcher.close, if I comment the line: it's fast 😿 FYI, I'm on macos 11.5.2 with node 14.17.6 and I tried with node 16.9.0 too. |
Can you debug this too https://github.com/webpack/watchpack/blob/master/lib/watchEventSource.js#L188? |
yes I passed here https://github.com/webpack/watchpack/blob/master/lib/watchEventSource.js#L194 then https://github.com/webpack/watchpack/blob/master/lib/watchEventSource.js#L75 So I can now reproduce easily the slowness on my laptop: const fs = require('fs');
const watchers = [];
for (let n = 0; n < 1200; n += 1) {
watchers.push(fs.watch(process.cwd()));
}
console.time('close');
for (let w of watchers) {
w.close();
}
console.timeEnd('close'); These fs.FSWatcher instances are slow to close (~4.7s on my laptop) |
Big thanks, we will investigate this in near future, but maybe problem deeply, i.e. in Node.js or maybe there are technical reasons for this... |
I'm working around this now by adding this to my webpack.config.js: const { watch } = require('fs');
// Ctrl + C is super duper slow because it has to close a bunch of fs.watch handles. Let's just skip
// all that.
// https://github.com/webpack/webpack-dev-server/issues/1479
process.once('SIGINT', () => {
Object.getPrototypeOf(watch('.')).close = () => {};
return true;
}); |
We will fix it in near future, anyway not graceful closing can corrupt file caches |
Checked watchpack's Any idea what's the point of watching those files and what is adding them? Thanks. |
Due resolving logic, I am thinking long closing is a bug in Node.js, What is os? |
I'm on macOS Catalina. I added Now that I'm checking the watched files in
Is this normal behavior? Seems to me like there are useless watchers but I don't understand this library. |
Yes, because you can add |
Seeing same issue in Webpack 5.53.0, macOS Big Sur, M1, Node 12.22.5. |
I have idea how to improve this, there are two approach:
So you can chose wait or close immediately |
How realistic case is it that force exit corrupts webpack cache or something like that? |
In stage when webpack try to write caches, it is based on many metrics, hard to say, but I think in this case webpack should skip broken cache and try to create new |
I'd eat my hat if leaving a dangling watch handle corrupts any file cache. My hack above just leaves the watch handles open, it doesn't touch anything else. The operating system is more than capable of cleaning our mess up. |
@laverdet yep hack above will be corrupt cache, it just fix Node.js problems with slow closing files. Here two problems:
|
The offer on eating my hat still stands. I just can't imagine a scenario in which a file would be corrupted by a dangling inotify handle. In fact, I'd go so far to say that any such corruption would warrant a CVE in the Linux kernel followed by a hushed patch by Google's top minds. On the other hand calling process.exit will almost definitely cause partially written files to be flushed to the filesystem since the process terminates with open descriptors (of the mode == "w" kind). I have a great deal of respect for your contributions to Webpack but I do think that leaving the watch handles open is a safer workaround in this case. |
There is another problems - developers middlewares, we can't know it is safe to close immediately or we need to do graceful shutdown, same for custom client/web socket server implementations, I think we need report problem with slow closing to Node.js. Anyway in the next release double pressing CTRL + C will close immediately process, so developer can choose what is better |
Hi, I am having an issue with might be related. I start WebpackDevServer from a script, but when I Cmd+C to close it, the script stops immediately (at least the terminal looks like it did), but then not only additional output appears from webpack (the line with "gracefully shutdown") but also, if i try to input characters such as up/down arrows they appear as I am wondering if i need to wait for webpack in anyway from within my script. I tried but did not work.
Maybe it is worth mentioning that if i send the SIGINT from In your opinion, is this related to the webpack - script interaction, or is it a terminal/zsh related issue (given that SIGINT is handled correct when coming from a source different than Cmd+C) ? |
Thanks for the clarification. |
Right, it's totally normal. Just remember the |
The only way it exits for me is if I run webpack directly from CLI (npx or package "scripts"). If I put it in a shell script it prints "Gracefully shutting down" but then never does, regardless of how many watchers there are. Also tried things like Another CMD+C does exit, but sometimes the dev server is still running in the background and have to manually kill processes on the port, especially if there are a lot of watchers. |
Adding I believe I figured out the reason that "first ^C graceful shutdown, second ^C force close" was not actually working — it's because the server was running |
Code
Running the dev server with:
yarn webpack-dev-server --progress
. I'm not including webpack configs since seems to be reproducing on a variety of projects, so I assume it's something that happens regardless of the config? (Happy to provide more info otherwise).Expected Behavior
Ctrl + C stops the dev server.
Actual Behavior
Ctrl + C does not do anything, dev server continues to compile modules.
May be a regression of #860, #1360?
The text was updated successfully, but these errors were encountered: