Webpack-dev-server: can't close webpack-dev-server --progress with Ctrl + C

Created on 29 Aug 2018  Â·  45Comments  Â·  Source: webpack/webpack-dev-server

  • Operating System: macOS High Sierra (10.13.6)
  • Node Version: v10.9.0
  • NPM Version: 6.2.0
  • webpack Version: 4.16.5
  • webpack-dev-server Version: 3.1.5
  • [x] This is a bug
  • [ ] This is a modification request

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?_

3 (important) question 4 (inconvenient) bug

Most helpful comment

will be fixed for webpack@5

All 45 comments

Could you try with v3.1.6 (#1432) ?

Woo-hoo! Missed that there's 3.1.6 available, works like a charm with it.

Oops, spoke too soon. It still reproduces on 3.1.6...

Still an issue with v3.1.9

Having the issue on Linux and Mac with webpack-dev-server v3.1.8.

Please create minimum reproducible test repo with steps

@SebT I've also had this issue, specifically when using the -theme react preset from the ReasonReact starter. I'm working on getting reproducible steps - it doesn't seem to happen in a dry environment, so I imagine it's some conflict with another file watcher that occurs after some period of use.

Edit: Alright, I've created a branch that consistently reproduces this here. To reproduce:

  1. Clone and install dependencies.

  1. Install bucklescript globally.
yarn global add bs-platform
  1. Start bucklescript watcher.
yarn start
  1. Start dev server.
yarn server
  1. Touch a Reason source file, eg:
touch src/components/Stateful/Stateful.re

At this point, the dev server gets stuck at Compiling..., with the logs looking something like

yarn server
yarn run v1.10.1
$ webpack-dev-server
ℹ 「wds」: Project is running at http://localhost:8000/
ℹ 「wds」: webpack output is served from /home/superhawk610/code/the-completionist/build/
ℹ 「wds」: Content not from webpack is served from /home/superhawk610/code/the-completionist/build/
ℹ 「wds」: 404s will fallback to /index.html
ℹ 「wdm」: Hash: d9fc1cbd98cbce78242b
Version: webpack 4.23.1
Time: 469ms
Built at: 10/31/2018 1:31:25 AM
     Asset       Size  Chunks             Chunk Names
  Index.js    1.2 MiB    main  [emitted]  main
index.html  257 bytes          [emitted]  
Entrypoint main = Index.js
[0] multi (webpack)-dev-server/client?http://localhost:8000 ./src/Index.bs.js 40 bytes {main} [built]
[./node_modules/ansi-html/index.js] 4.16 KiB {main} [built]
[./node_modules/ansi-regex/index.js] 135 bytes {main} [built]
[./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [built]
[./node_modules/reason-react/src/ReactDOMRe.js] 2.6 KiB {main} [built]
[./node_modules/reason-react/src/ReasonReact.js] 22.2 KiB {main} [built]
[./node_modules/strip-ansi/index.js] 161 bytes {main} [built]
[./node_modules/url/url.js] 22.8 KiB {main} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:8000] (webpack)-dev-server/client?http://localhost:8000 7.78 KiB {main} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.58 KiB {main} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
[./node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 75 bytes {main} [built]
[./src/Index.bs.js] 417 bytes {main} [built]
[./src/components/App/App.bs.js] 1.57 KiB {main} [built]
    + 32 hidden modules
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
    [./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html] 466 bytes {0} [built]
    [./node_modules/lodash/lodash.js] 527 KiB {0} [built]
    [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 489 bytes {0} [built]
    [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {0} [built]
ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...

Ctrl+C exits the process but leaves the server running

$ ps -ef | grep webpack
superha+ 23562 23551  0 01:31 pts/2    00:00:00 /bin/sh -c webpack-dev-server
superha+ 23563 23562 95 01:31 pts/2    00:06:22 node /home/superhawk610/code/the-completionist/node_modules/.bin/webpack-dev-server
superha+ 24114 22506  0 01:38 pts/1    00:00:00 grep --color=auto webpack

The error (in this case, at least) appears to occur when the dev server gets stuck compiling. Ctrl+C at this point doesn't actually end any processes - all 3 processes listed above remain active after sending SIGINT to the yarn process.

FWIW, I'm using VSCode with the Reason/OCaml extension.

Edit: Alright, this latest commit consistently causes webpack to freeze at Compiling... and orphan the dev server process on SIGINT. It's preventing me from any further development :slightly_frowning_face:

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.
webpack-dev-server 3.1.1, Mac Sierra

If somebody can reproducible test please post how here, we can fix it asap

The error (in this case, at least) appears to occur when the dev server gets stuck compiling. Ctrl+C at this point doesn't actually end any processes - all 3 processes listed above remain active after sending SIGINT to the yarn process.

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
(instructions in Readme)

@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.

OS:

-> sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.6
BuildVersion:   17G3025

Using the above repo:

wds-kill-failure

Every time the progress bar is duplicated I am pressing ^C. Also I need to press it to bring the prompt back at the end.

(Note that @nfm is experiencing this on Ubuntu so it's not just macOS)

@danburzo @rhys-vdw Very thanks for repo/screenshot and feedback. I will try to find Mac OS system on this week and fix problem. Anyway feel free to investigate why it is happens, code for killing process here https://github.com/webpack/webpack-dev-server/blob/927a2b38d4d3a5d8fd50dfce0343634d46fa8a92/bin/webpack-dev-server.js#L48. Maybe signal have another value?

@danburzo Awesome, reproduce problem on linux (Ubuntu) too

One interesting thing - it is happens when you try to require('webpack'), if you change this on console.log all works fine

Problem found, we use server.close before run process.exit (close all connections, watchers and etc stuff). server.close use webpackDevMiddleware.close method, what use watching.close (when you in not lazy mode - using webpack-dev-server), but watching.close wait until all was compiled.

What we need to fix all problem with CRTL+C:

  1. Implement Watching.kill() method in webpack
  2. Add kill option to webpackDevServer.close (by default false)
  3. Use webpackDevServer.close(cb, true) in Server.close.

If somebody have time to help with this issue PRs welcome

I want to work on this issue. How to get started?

@bhavya9107

  1. Implement Watching.kill() method in webpack

Here https://github.com/webpack/webpack/blob/master/lib/Watching.js

What is expected behavior of kill method?

@bhavya9107 immediately kill watch on webpack side

why can't we just process.exit()

if we want to close a specific process then we need specific close and kill methods, otherwise process.exit() is fine according to me. What you say @evilebottnawi

@bhavya9107 because when you process.exit() you kill process immediately, but in this moment somebody/something can write file to fs or do other async call and it is bad

still in 3.2.1
my solution:

// webpack.development.js
const kill = require('tree-kill')

const pid = process.pid
process.on('SIGINT', function () {
  kill(pid, 'SIGKILL')
})

@caolvchong it can kill some processes what writing files or other stuff what can break you app

Any update on this?

@evilebottnawi A bug was introduced when the setupExitSignals helper was added, related to this issue. The problem is that server is getting passed by value as undefined into the setupExitSignals function, and the function will never see the defined server object:

https://github.com/webpack/webpack-dev-server/blob/a28800dbe3b490360fd41c41802483c14e7d01db/bin/webpack-dev-server.js#L21-L23

Should we fix this on master or next?

@Loonride let's fix it in master

Can we close this issue? /cc @evilebottnawi @Loonride

fm... It doesn't seem fixed using [email protected]. I'll check this issue.

@hiroppy My fix did not solve the issue, it only changed the behavior slightly to remove a related bug. This still has to be done: https://github.com/webpack/webpack-dev-server/issues/1479#issuecomment-442492922

oh, ok, thanks.

have you guys found this error when press ctrl+C

if (serverData.server) {
                     ^
TypeError: Cannot read property 'server' of undefined
    at process.on (/Users/liangjiawen/workspace/recore/test/node_modules/webpack-dev-server/lib/utils/setupExitSignals.js:8:22)
    at process.emit (events.js:194:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1

[email protected]

@javaxiu good catch, can you send a PR with fix - if (serverData && serverData.server)?

This is still happening for me in webpack-dev-server 3.9.0 (and webpack 4.41.2.) When I press Ctrl+C, I get returned to the shell prompt, but I still see the WebpackBar progress until the compilation has finished.

I'm running:

NODE_ENV=development webpack-dev-server --inline --hot --config webpack.config.js

@caolvchong's workaround works:

const kill = require('tree-kill')

const pid = process.pid
process.on('SIGINT', function () {
  kill(pid, 'SIGKILL')
})

will be fixed for webpack@5

Seeing the same happening with webpack-dev-server 3.10.1, webpack 4.41.5 on Linux, compilation progress continues.
FWIW, Ctrl+ (sends SIGQUIT) works immediately for me. (same caveats apply as other "kill" solutions)

Hey there folks I also seem to have this issue when running gatsbyjs or nextjs projects. I am on a windows 10 machine using webstorm. ctrl c will work a few times but then gets stuck. is there any permanent solution to it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wojtekmaj picture wojtekmaj  Â·  3Comments

uMaxmaxmaximus picture uMaxmaxmaximus  Â·  3Comments

StephanBijzitter picture StephanBijzitter  Â·  3Comments

da2018 picture da2018  Â·  3Comments

mrdulin picture mrdulin  Â·  3Comments