node - localhost connection error ECONNREFUSED ::1:4723 in node 17 and node 18
source link: https://serebrov.github.io/html/2023-07-28-node-econnrefused-localhost.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
node - localhost connection error ECONNREFUSED ::1:4723 in node 17 and node 18
The upgrade to node 18 broke some things on CI that looked strange at first:
- The
npx wait-on
checks started showing connection errors. - The webdriver.io tests for native apps failed, also with connection errors.
The errors look like this:
Unable to connect to “http://localhost:4723/”, make sure browser driver is running on that address. .. ERROR webdriver: RequestError: connect ECONNREFUSED ::1:4723
The localhost
resolves to IPv6 address ::1
and the connection fails as the server (Appium) only runs on IPv4 address (127.0.0.1
).
The problem is caused by the change in Node’s DNS lookup procedure and
starting with Node 17, it does not resolve localhost
to 127.0.0.1
(IPv4 address)
by default (instead, it got resolved to the IPv6 ::1
address which caused a connection error):
Node.js no longer re-sorts results of IP address lookups and returns them as-is (i.e. it no longer ignores how your OS has been configured)
Discussion is here: https://github.com/nodejs/node/issues/40702.
Possible solutions are:
- Replace
127.0.0.1
withlocalhost
on the client side - Update your server applications to listen to both IPv4 (
127.0.0.1
) and IPv6 addresses (::1
) - Downgrade to Node 16 or upgrade to Node 20 (one more change here to automatically fallback to IPv4, so it works again).
For example, to fix the problem with npx wait-on http://localhost:8080
, change it to npx wait-on http://127.0.0.1:8080
.
If you also control the server-side code, consider starting the server both on IPv4 and IPv6 addresses.
It becomes more complex if you do not have control over either the client or the server code.
In the case of native webdriver.io tests, it both starts the server (Appium)
and acts as a client, trying to connect to it via http://localhost:4723
.
I found a configuration option to change the
port,
but I didn’t find a way to configure the Appium server address
(to change localhost
to 127.0.0.1
).
As a simpler solution, I switched to Node 20 before running tests:
nvm install 20
nvm use 20
cd e2e-webdriver
npm run test:ios
This way tests run with Node 20 that has a fall-back to IPv4 and the connection works.
Recommend
-
11
Submitted by NanoDano on Wed, 04/24/2019 - 19:38 Problem When attempting to use SSH client in Fedora 29 within a VMWare Player virtual machine, I would...
-
13
Linked Server error: Named Pipes Provider: Could not open a connection to SQL Server [53] – MSDN TSQL forum –> Question: I am trying to create a linked server of a remote server in my local system....
-
6
Connection ErrorBad gateway 141.164.63.164/c50d603 29/Jun/2021:19:39:48 +0800
-
41
V2EX › git ssh -T [email protected] 出现 nc: Proxy error: "HTTP/1.1 200 Connection established" 的错误
-
1
Error establishing a database connection Overview You may see the following error when visiting your site: Error establishing a database connection T...
-
9
Localhost returns an error instead of my web...
-
5
Sven Knöpfler 4 days ago Error while setting up a live connection in SAC to DWC 112 Views ...
-
7
LastPass Error: We couldn’t contact the server. Check Your internet connection and try again. By Tony Perez...
-
2
❌MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'❌如何解决 https://www.chenweiliang.com/cwl-30369.html 解决方案点进上面链接获取详细教程👨💻👩💻💻🔒
-
3
I couldn't open cloud procets in Eclispse ::: localhost error Skip to Content...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK