-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Closed
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
when I start vite app and then start koa server OR start koa server and then start vite app, no indication of port conflict.
And I use Google Chrome to access the page 127.0.0.1:3000, the page display content about the latter server content.
Reproduction
This question reminds me of PM2——master-slave mode, but vite didn't handle it well. I try to read the vite's source code, but I am worried about misunderstanding, so come here to issue. If this is a problem, can you provide solutions or fix it as soon as possible?
thanks.
System Info
@vite: 2.6.4,
@node: 14.16.0,
@koa: 2.13.3,
@Google: Chrome: 94.0.4606.71 (official version) (x86_64),
@OS: macOS Catalina 10.15.7,
@JavaScript: V8 9.4.146.18,Used Package Manager
npm
Logs
nullValidations
- Follow our Code of ConductRead the Contributing Guidelines.Read the docs.Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.The provided reproduction is a minimal reproducible example of the bug.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
classmatewu and zrev2220classmatewuclassmatewu and poyoho
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
haoqunjiang commentedon Oct 24, 2021
Not necessarily a critical bug.
Your koa server listens to
0.0.0.0or::by default, not127.0.0.1(which is the Vite default).As Node.js sets all sockets with the
SO_REUSEADDRflag (explanation: https://medium.com/@eplawless/node-js-is-a-liar-sometimes-8a28196d56b6), it allows other sockets to reuse the same port as long as it doesn't listen to the exact same address.The problem here is that Vite chooses to display
localhostwhile the actually bound address is127.0.0.1; this could be misleading in some rare edge cases, like this one.Take my network environment as an example (may not be very accurate, I'm not a network expert):
/etc/hosts, I have localhost bound to both127.0.0.1and::1, meaning thatlocalhostresolves to::1when IPv6 is available;127.0.0.1:3000by default;::, which also accepts connections from::1;localhost:3000, it's equivalent to::1:3000as I'm in an IPv6 environment. So I end up hitting the koa server;127.0.0.1:3000, I can still visit the Vite server.haoqunjiang commentedon Oct 24, 2021
So the solution could be either of the following:
127.0.0.1and::1(most intuitive, but I don't know how to implement that)::1when IPv6 is available, and127.0.0.1otherwise (most conventional, but would still surprise people sometimes)localhostwhen it's actually127.0.0.1localhostis now incompatible with node's #7075smithyj commentedon Jun 3, 2022
This problem is solved,set
server.host=0.0.0.0,example config:smithyj commentedon Jun 3, 2022
@sodatea This issues should closed
localhostinstead of127.0.0.1#8543