0

I have a vue app created with the webpack-simple template.

I want to use an static port, so I hard code the port in the devServer property in the file webpack.config.js

devServer: {
        historyApiFallback: true,
        noInfo: true,
        overlay: true,
        port: 1123
    },

The first time that I run npm run dev everything works fine. After I close the process with ctrl+c (using git bash in windows) and retry running npm run dev an error occurs telling me that the port is currently in use. If I change the port the first time it works then it repeats the same error (again and again).

I check the processs that is using the ports and it's node. I don't understand why node keep listening to those ports after I hit ctrl+c.

My dev script:

"dev": "cross-env NODE_ENV=development webpack-dev-server --hot"

Info

OS: Windows
Terminal: Git Bash
Node: v9.5.0
NPM: v5.6.0
Webpack: 3.6.0
Webpack-Dev-Server: 2.9.1
Larizza Tueros
  • 609
  • 5
  • 10
  • FWIW, https://github.com/Microsoft/node-pty/issues/7 may be the issue. I was seeing the same thing and upgrading Git (with bash) to 2.18.0 seems to have resolved the issue for me. – Brian J. Miller Jun 22 '18 at 21:22

1 Answers1

0

If the process exits abruptly, it doesn't close cleanly the listening server. The node process is terminated but the operating systems keeps the port open (in TIME_WAIT state) for a given amount of time to allow for the queues of packets to empty (see the socket FAQ and section "2.7 Please explain the TIME_WAIT state.". In node, you can mitigate this problem by trying to close the server on exit and uncaughtException events. See this reply to a related question.

Marco Pantaleoni
  • 2,529
  • 15
  • 14
  • I have the same issue and the node process is not terminated (it can be seen via the windows task manager) but not via `ps` in the shell, and the socket is not in a `TIME_WAIT` status, it is still `LISTENING` as seen via `netstat -ao`. It is almost as if the node process has been dissociated from the bash shell. – Brian J. Miller Jun 22 '18 at 21:04