Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

[Bug] Serve port and hot port conflict on Windows #135

Closed
1 of 3 tasks
meteorlxy opened this issue May 12, 2018 · 3 comments
Closed
1 of 3 tasks

[Bug] Serve port and hot port conflict on Windows #135

meteorlxy opened this issue May 12, 2018 · 3 comments

Comments

@meteorlxy
Copy link

meteorlxy commented May 12, 2018

  • Operating System: Windows 10
  • Node Version: v8.11.1
  • NPM Version: v5.5.1 (yarn v1.6.0)
  • webpack Version: 4.8.1
  • webpack-serve Version: 0.3.2

This issue is for a:

  • bug
  • feature request
  • modification request

Code

API
const serve = require('webpack-serve')
const compiler = /* our compiler */
serve({
    compiler,
    host,
    port: 8081
})

Expected Behavior

Works well

Actual Behavior

「serve」:  { Error: listen EADDRINUSE 127.0.0.1:8081
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at Server.setupListenHandle [as _listen2] (net.js:1367:14)
    at listenInCluster (net.js:1408:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1517:7)

How Do We Reproduce?

It's related to:

webpack-serve/lib/server.js

Lines 117 to 118 in c9235b5

getPort({ port: options.port, host: options.host }),
getPort({ port: options.hot.port || 8081, host: options.host }),

If all ports are free, only 8081 port have this error. As those two getPorts will both find port from 8081 and then use the same port.

The core problem is that those two getPorts have the possibility to get a some port and cause conflict

We noticed that at vuejs/vuepress#424

@shellscape
Copy link
Contributor

@meteorlxy this isn't a bug - that's the default port for the WebSocket server. If you're choosing to use that as the primary web serve's port as well, then you're configuring this for failure out of the gate. The solution is simply not to do that.

@meteorlxy
Copy link
Author

meteorlxy commented May 12, 2018

@shellscape
It's possible that:

const serve = require('webpack-serve')
const compiler = /* our compiler */
serve({
    compiler,
    host,
    port: 8080
})

But 8080 is not free, then cause this error.

Or, if 8080~8085 or so are all in used, then the two getPorts will both choose 8086

I think we could make it cleverer to avoid it.

@meteorlxy
Copy link
Author

That means, to avoid the second getPort to chose the result of first getPort

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants