I have been using k6 for a couple of days to do load testing against and API in several different environments and chase down some bugs.
Everything was going great, until suddenly it started failing locally.
All requests result in the following error:
Request Failed error="Get
http://localhost:8000
: dial tcp [::1]:8000: getsockopt: connection refused"
This only occurs in k6; I can still call the local API successfully through a browser, Postman, and cURL.
Is there any way to get more information out of k6 and figure out why it can't connect anymore?
The error message says that localhost
is resolving to an IPv6 address (::1
in [::1]:8000
) so if your API is only listening on the IPv4 127.0.0.1
but your localhost
resolves to both an IPv4 and an IPv6 address (k6 supports both) then that would explain the error.
If you look in your /etc/hosts
file you probably have entries for localhost
that looks like this:
127.0.0.1 localhost
::1 localhost
fe80::1%lo0 localhost
I'm not sure why the lookup of localhost
changed for you all of a sudden from IPv4 to IPv6, but might be that there are variables in
your system's address selection algorithm (see for example [1] for iOS/macOS, and more generally [2] which Go's internal resolver uses when it doesn't have to go through the system's resolver) that causes the switch based on things like historical TCP RTT (which is mentioned in [1] as a factor).
[1] https://www.ietf.org/mail-archive/web/v6ops/current/msg22455.html
[2] https://www.rfc-editor.org/rfc/rfc6724
Use 127.0.0.1
instead of localhost
will solve your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With