API timeouts all day from netlify-cli

Hi there. Have been using it happily for ages but today the netlify command is having a bad one.

Lots of these:

FetchError: request to https://api.netlify.com/api/v1/sites?name=v5.johnnydecimal.com&filter=all&page=1&per_page=100 failed, reason: Socket connection timeout

Not sure if the server should be pingable, but it ain’t:

$ ping api.netlify.com
PING net-nf-server-api-lb-cmh-prod-1012841289.us-east-2.elb.amazonaws.com (18.223.153.182): 56 data bytes
Request timeout for icmp_seq 0

$ netlify deploy
 ›   Error: request to https://api.netlify.com/api/v1/sites?filter=all failed, reason: Socket connection timeout
..om [feature/content-collection|✔] ❯❯❯ 

I’ve tried un/re-installing, tried the new v15.0.2 and back to v14.4.0, tried un/re-linking my site, I tried it all!

Doesn’t matter what I do: netlify link, netlify deploy, they all fail.

Suffice to say that my network connection is A-OK and various network tests confirm that everything appears to be well at my end.

I’m in Canberra, Australia.

Same this morning.

$ netlify deploy
Deploy path:        /Users/john/dev/johnnydecimal/v5.johnnydecimal.com/dist
Configuration path: /Users/john/dev/johnnydecimal/v5.johnnydecimal.com/netlify.toml
Deploying to draft URL...
✔ Finished hashing 
✔ CDN requesting 5 files
✔ Finished uploading 5 assets
⠴ Waiting for deploy to go live... ›   Warning: 
{
  "type": "system",
  "errno": "ERR_SOCKET_CONNECTION_TIMEOUT",
  "code": "ERR_SOCKET_CONNECTION_TIMEOUT",
  "url": "https://api.netlify.com/api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/deploys/645d59c4067e97008dab454f",
  "data": {
    "method": "GET",
    "headers": {
      "User-agent": "netlify-cli/14.4.0 darwin-arm64 node-v20.1.0",
      "accept": "application/json",
      "Authorization": "Bearer [hash]"
    }
  }
}

 ›   FetchError: request to https://api.netlify.com/api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/deploys/645d59c4067e97008dab454f failed, reason: Socket connection timeout

Hi, @johnnydecimal. I must first clarify that the ping failure is normal and expected. You will never be able to successfully ping the API IP addresses, even with a working connection to the API. Pinging is blocked for all IP addresses used for the API.

That said, the API endpoint is definitely up and working for the vast majority of people using Netlify so this is most likely a local networking issue.

I would recommend testing the URL locally using curl. For example, using something like this:

curl -svo /dev/null https://api.netlify.com/api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/deploys/645d59c4067e97008dab454f

If the curl command times out then you will know it is a local networking issue as that endpoint works for me when I test it.

If the request does timeout I would next install dig and then run the command below:

dig api.netlify.com

The output of the curl command and the dig command may reveal more information about the root cause of this issue. If you would please share the output of the two command here, we will be here to keep troubleshooting.

Thanks @luke, it’s still flaky for me here.

$ netlify serve
 ›   Error: Failed retrieving addons for site d7ba03bd-cd74-45c4-bf51-8440819316b3:
request to https://api.netlify.com/api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/service-instances
failed, reason: Socket connection timeout.
Double-check your login status with 'netlify status'
or contact support with details of your error.

So let’s go curling…

$ curl -svo /dev/null https://api.netlify.com/api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/service-instances
*   Trying 3.17.168.152:443...
* Connected to api.netlify.com (3.17.168.152) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* [CONN-0-0][CF-SSL] (304) (OUT), TLS handshake, Client hello (1):
} [320 bytes data]
* [CONN-0-0][CF-SSL] (304) (IN), TLS handshake, Server hello (2):
{ [100 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [4952 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
{ [1 bytes data]
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=netlify.com
*  start date: Feb  9 00:00:00 2023 GMT
*  expire date: Nov 11 23:59:59 2023 GMT
*  subjectAltName: host "api.netlify.com" matched cert's "*.netlify.com"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M02
*  SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* h2h3 [:method: GET]
* h2h3 [:path: /api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/service-instances]
* h2h3 [:scheme: https]
* h2h3 [:authority: api.netlify.com]
* h2h3 [user-agent: curl/7.87.0]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x127013400)
> GET /api/v1/sites/d7ba03bd-cd74-45c4-bf51-8440819316b3/service-instances HTTP/2
> Host: api.netlify.com
> user-agent: curl/7.87.0
> accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 401 
< date: Sun, 14 May 2023 06:25:28 GMT
< content-type: text/html
< content-length: 0
< cache-control: no-store
< pragma: no-cache
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< timing-allow-origin: https://app.netlify.com, https://www.netlify.com
< vary: Origin
< www-authenticate: Bearer realm="user"
< x-content-type-options: nosniff
< x-frame-options: ALLOWALL
< x-nf-srv-version: 982a45bd
< x-request-id: c0c629da-adb0-4067-ac3f-ae07002725bc
< x-runtime: 0.002305
< 
{ [0 bytes data]
* Connection #0 to host api.netlify.com left intact

That might help you, I’m not sure how that’s meant to look. But it works every time.

Notably this was failing, so I switched network connections entirely – I’m now tethering off my 5G connection – and the result is the same.

This was working earlier, and then it just stopped. ¯\_(ツ)_/¯

The curl indicates that you’re able to connect to Netlify API without issues. So this is not a network issue at least.

Would you be using Node 20 by any chance? Looks like recently this issue was fixed: v20.0.0 ERR_SOCKET_CONNECTION_TIMEOUT when sending http request to some domains · Issue #47822 · nodejs/node · GitHub. That would also explain why you’re able to connect to Netlify API, but the CLI fails.

Yeah, Node 20.1.0. The cli is working again this morning, if it fails later I’ll drop back to Node 18 and test. Thanks for the info.

Okay, interesting. Just had a failure, dropped back to Node v18.16.0, now it works. Let’s see if it stays that way…