-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: take the first network found instead of the last one #5411
base: master
Are you sure you want to change the base?
Conversation
…res the same behavior as 5.0.4
The committers listed above are authorized under a signed CLA. |
@mahdikhashan and @alexander-akait you worked on #5255 what do you think of the change? |
@vincentfretin hm, I think it is a breaking change too, in such case I recommend to provide a value for host... We can't detect a right value in such situation |
On Ubuntu it seems I always have loopback, ethernet, wifi and docker bridge in this order. const os = require("os");
os.networkInterfaces() In the previous code it also returned the first matching network address What order do you have in other OSes you tested? And why don't you have the issue? Maybe you don't have docker on your machine? |
I used a mac - a recent one with silicon chip. |
@mahdikhashan on macOS what do you have with |
I don't have access to my code setup now, if I remember correctly I had multiple networks - I remember in my first changes, related to this current issue - I had selected the first interface. |
In #5255 the code was taking the last one: let host;
Object.values(os.networkInterfaces())
...
.forEach((network) => {
host = network.address;
if (host.includes(":")) {
host = `[${host}]`;
}
});
// host is the last one and in the latest commit with changes made by @alexander-akait it's now let host;
const networks = Object.values(os.networkInterfaces()) ...
for (const network of networks) {
host = network.address;
if (host.includes(":")) {
host = `[${host}]`;
}
}
// host is the last one both code are equivalent and take the last one. In default-gateway, it returned the first one: |
It would be interesting to know where Node.js takes order for |
https://github.com/nodejs/node/blob/a08129cb0d8ff1df3ce45c3910cae1fc72aaf080/lib/os.js#L271 getifaddrs doesn't mention any order, so yeah it seems to be an undefined behavior. If I remove host key in my webpack.config.js devServer config
that's another issue, but it listens correctly on 192.168.1.15 I switched now from
to
It shows:
From a developer experience perspective, it would be better imo if it showed this:
similar to how http-server does it. That's really what my issue it about, be able to click on the address I want without knowing in advance what is my local ip. |
Can you provide reproducible example, because this should never happen |
I had this config in my file
devServer.options.host was undefined here.
|
You need to take this options from real Anyway does your dev server work using Only thing that we can improve it is output, we don't want to change logic of getting IPs, because it can break logic for other developers |
|
PR welcome |
I have the same issue on My Macbook Air M1. Before, the IP showed in console when running the server matched my local IP. Now it's showing the IP of a different interface (en0 is my local IP and server shows en5 as shown by ifconfig command). My local IP is also the first one in the list as shown by @vincentfretin when logging |
@alexander-akait I'm curious if we revert back to using the first interface, you said it would be a breaking change. Do you currently use a system where taking the first interface would chose the wrong interface for you? |
@vincentfretin I'm not sure about this because when testing on one of the computers I encountered the opposite problem, where the choice of the first interface was incorrect, I can't judge how common this is, because earlier we had a separate package that also checked the functionality, now as you can see the logic is a little different, I don't mind making changes, but I wouldn't want after the fix and the new release I to receive feedback where I would have to revert and raise the issue again
Ok let's try your solution to the problem, hopefully we won't break it for many users |
I've run the tests, let's see how they go. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5411 +/- ##
===========================================
- Coverage 90.29% 76.42% -13.87%
===========================================
Files 15 13 -2
Lines 1577 1977 +400
Branches 601 723 +122
===========================================
+ Hits 1424 1511 +87
- Misses 140 403 +263
- Partials 13 63 +50 ☔ View full report in Codecov by Sentry. |
It seems the new test passed. |
Yeah, I just don’t understand why coverage is broken, we need to resolve it before merge, maybe testes are not executing after new tests… |
Take the first network found instead of the last one that may be the docker bridge. This restores the same behavior as 5.0.4, this fixes a regression introduced in 5.1.0 where the default-gateway dependency was dropped.
For Bugs and Features; did you add new tests?
I tried to include a test and run it with
npm run test:only test/cli/hot-option.test.js
but I can't make it run on my machine, it's just blocking at
RUNS test/cli/hot-option.test.js
no idea why.
I also have lots of failing tests and other files blocking like this when I'm testing on my machine.
Hopefully the CI may execute the test, finger crossed.
Motivation / Use-Case
On version 5.0.4 with
--host local-ip
on Ubuntu, it returnedhttps://192.168.1.15:8080
On 5.1.0 and 5.2.0 it returns
https://172.17.0.1:8080
that is the docker bridge, not so useful.The new code introduced in #5255 was taking the last network of the networks array.
The change in this PR take the first one in networks array.
Breaking Changes
No breaking change, this fixes a regression introduced in 5.1.0 where the default-gateway dependency was dropped.
Additional Info