-
Notifications
You must be signed in to change notification settings - Fork 5
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
IPv6 getaddrinfo ENOTFOUND Error #18
Comments
There was a temporary change in NodeJS where it returned The error you're seeing is an interesting one, and seems likely to be related to your Docker network setup. I suspect that although NodeJS believes the network is IPv6-capable, in practice it isn't. A simple workaround would be to listen on an IPv4 address explicitly: before(async () => {
server = await app.listen(0, '127.0.0.1');
}); As an aside, the URL format for connecting to an IPv6 address is |
I investigated this further and found that:
Below are examples of request calls that succeed or fail: For post requests either with import request from "supertest";
import wsrequest from "superwstest";
...
// ✅ await request('127.0.0.1:' + server.address().port)
// ✅ await request('http://127.0.0.1:' + server.address().port)
// ❌ await request('[::1]:' + server.address().port)await request('[::1]:' + server.address().port)
// ❌ await request('http://[::1]:' + server.address().port)
// ❌ await request(`[${server.address().address}]:${server.address().port}`)
// ❌ await request(`http://[${server.address().address}]:${server.address().port}`)
// ✅ await request(server)
// ✅ await wsrequest('127.0.0.1:' + server.address().port)
// ✅ await wsrequest('http://127.0.0.1:' + server.address().port)
// ❌ await wsrequest('[::1]:' + server.address().port)
// ❌ await wsrequest('http://[::1]:' + server.address().port)
// ❌ await wsrequest(`[${server.address().address}]:${server.address().port}`)
// ❌ await wsrequest(`http://[${server.address().address}]:${server.address().port}`)
// ❌ await wsrequest(server)
console.log(server.address());
// { address: '::', family: 'IPv6', port: 46323 }
...
For WebSocket requests with import wsrequest from "superwstest";
...
// ❌ await wsrequest('127.0.0.1:' + server.address().port)
// SyntaxError [Error]: Invalid URL: 127.0.0.1:46323/subscriptions
// ✅ await wsrequest('http://127.0.0.1:' + server.address().port)
// ✅ await wsrequest('ws://127.0.0.1:' + server.address().port)
// ❌ await wsrequest('[::1]:' + server.address().port)
// SyntaxError [Error]: Invalid URL: [::1]:46323/subscriptions
// ✅ await wsrequest('http://[::1]:' + server.address().port)
// ✅ await wsrequest('ws://[::1]:' + server.address().port)
// ❌ await wsrequest(`[${server.address().address}]:${server.address().port}`)
// ✅ await wsrequest(`http://[${server.address().address}]:${server.address().port}`)
// ✅ await wsrequest(`ws://[${server.address().address}]:${server.address().port}`)
// ✅ await wsrequest(server)
... Using Interestingly, The documentation states:
Is there logic that dynamically changes the protocol based on the request type? Could this behavior interfere with request(server) when making a POST request over IPv6? I'm eager to help resolve this issue and am willing to run additional tests or make code changes with some guidance. |
After a bit of digging, I found the root issue in superagent (which is used by supertest) Specifically, this line tries to set the new URL('http://[::1]:8080').hostname // [::1]
http.request({ port: 8080, host: '[::1]' }) // fails
http.request({ port: 8080, host: '::1' }) // fine I'd recommend reporting this to superagent, since it does try to be IPv6 compatible (and has plenty of IPv6 handling code elsewhere). On the differences you noted: supertest will always assume servers are available at When supertest's methods are proxied via superwstest, the server address code from superwstest is still used (hence it attempting to connect via IPv6, triggering the bug in superagent) |
I have reported this in the relevant library here: ladjs/superagent#1828 |
I'm using supertest to test HTTP requests and would like to use superwstest for WebSocket testing. My HTTP request tests with supertest work as expected. Here's a simplified version of my code:
According to the superwstest documentation, I should be able to replace:
with:
However, when I do this, I encounter the following error:
Interestingly, if I explicitly request the server with:
everything works as expected. But a request to:
http://:::<port>/
does not work, suggesting an issue with how IPv6 addresses are being handled.
I've noticed that superwstest includes checks for different Node.js versions. Could there have been a recent change in how Node.js handles IPv6 addresses, which might be causing this issue?
Any guidance or insights on resolving this would be appreciated!
Environment:
Node.js: 23.4.0
Runtime: Docker container
The text was updated successfully, but these errors were encountered: