Getting ECONNREFUSED, but access via Apollo Studio works

I have some server-side code that instantiates an ApolloClient to connect to an Apollo Server that I’m running.

When I try to issue a query, I get:

 Error editing product request to http://localhost:3000/apps/gql/sutrob88-e04e-4970-955d-97cf35d3e9ab failed, reason: connect ECONNREFUSED ::1:3000 

However, if I drop http://localhost:3000/apps/gql/sutrob88-e04e-4970-955d-97cf35d3e9ab into a browser, the Apollo Studio comes up without any issues. So, clearly, the server is responsive on port 3000

One thing I noticed is that it’s reporting that it can’t connect to ::1:3000. I know that ::1 is the IPv6 version of localhost. I also know that the Express vhost that maps to my Apollo server probably doesn’t have that as a supported vhost.

So, if that’s the issue, my question is probably "why is my ApolloClient using IPv6 and how can I prevent it. Alternatively… what’s going on here??

I’d try using the IPv4 localhost/loopback address first (127.0.0.1) to remove the IPv6/v4 ambiguity as you’ve noted.

1 Like

Yep! That fixed it!

Thanks!

For the curious - I think this is actually a Node issue rather than an Apollo server or client issue.

Node has to resolve localhost to an IP address, and it does so with a request to the underlying operating system. There’s no guarantee about whether this is 127.0.0.1 or ::1 TBH, I’m not sure whether there’s even a guarantee that the resolution is “stable” over time.

1 Like