octokit / rest.js

GitHub REST API client for JavaScript

Home Page:https://octokit.github.io/rest.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed, reason: socket hang up and status 500

hawx1993 opened this issue · comments

Checklist

Environment

Versions
19.0.44

What happened?

RequestError [HttpError]: request to https://api.github.com/repos/hawx1993/heaven-docs/contents/%2Fpackages%2Fheaven%2Fsrc?ref=master failed, reason: socket hang up at /Users/trigkit4/heaven-code-helper/node_modules/@octokit/request/dist-src/fetch-wrapper.js:96:15

  status: 500,
  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/hawx1993/heaven-docs/contents/%2Fpackages%2Fheaven%2Fsrc?ref=master',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-rest.js/19.0.4 octokit-core.js/4.0.5 Node.js/14.18.1 (darwin; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound register] }
  }

and as you can see, we can easily open the link api: https://api.github.com/repos/hawx1993/heaven-docs/contents/%2Fpackages%2Fheaven%2Fsrc?ref=master
so, not the github issues

Minimal test case to reproduce the problem

const octokit = new Octokit({
  auth: GITHUB_TOKEN,
});
await octokit.repos.getContent({
      owner: 'hawx1993',
      repo: 'heaven',
      path: '/packages/heaven/src',
      ref: 'master',
    });

and throw upper error

What did you expect to happen?

can get normal response data from github

What the problem might be

Hi @hawx1993! 👋🏻 Thanks for reaching out.

It sounds like there is a connectivity issue between your machine and api.github.com.

The following code works for me locally (I changed the repo from heaven to heaven-docs, as it looks like that's the correct value!):

const octokit = new Octokit();

const response = await octokit.rest.repos.getContent({
    owner: 'hawx1993',
    repo: 'heaven-docs',
    path: '/packages/heaven/src',
    ref: 'master',
});

console.log(response.data);

I have some follow-up questions:

  1. How quickly does the code error? Does it take a few seconds? Or is it instant?
  2. Is this code failing on your local development machine, or is it some other environment (e.g. a cloud provider)?
  3. Are you able to reach api.github.com with a simple HTTP request from that environment? (e.g. curl https://api.github.com --verbose)

@timrogers hi, there!
this is my curl msg as below:

 curl https://api.github.com --verbose
*   Trying 20.205.243.168:443...
* Connected to api.github.com (20.205.243.168) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.github.com:443
* Closing connection 0
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.github.com:443

How quickly does the code error? Does it take a few seconds? Or is it instant?

is instant. I request github api meybe 100times per seconds

Is this code failing on your local development machine, or is it some other environment (e.g. a cloud provider)?

local mac machine. but I can open https://api.github.com/repos/hawx1993/heaven-docs/contents/%2Fpackages%2Fheaven%2Fsrc?ref=master on my browser.

I use axios , and it's normal

image

added the error msg pic

Thanks! It looks like your machine is having some kind of SSL or TLS issue with connecting to api.github.com, but I'm not sure why. What happens if you try to visit https://api.github.com/ in a browser?

@timrogers

{
    "message": "API rate limit exceeded for 172.105.122.83. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
    "documentation_url": "https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"
}

@timrogers it seems my token has been limited , can I use octokit to work through it by pass same params?

image
now it's normal, but I still can't get normal response by use octokit

It does seem that your IP has been rate limited, but the issue you are having with Octokit is a different issue, as you aren't even getting a response.

Looking at the curl error message, it seems like there is a problem with the LibreSSL installation on your machine. That stops curl from talking to GitHub, and it is also likely to stop Octokit from talking to GitHub. You will need to figure out what is going on with that SSL setup, which is independent from Octokit. Sorry ☹️

image

I can get normal response by use axios

That's surprising! In that case, I'm not sure what the issue is. It's odd that it would work in Axios but not node-fetch, given that they both should use Node's http module under the hood as far as I know.

@octokit/js-community Any ideas?

I request github api meybe 100times per seconds

That could definitely be the problem. If you send more than ~1 request per second over a prolonged time you will be flagged in some way or another. The same request works through curl and the browser because you send a single request.

Another idea: can you remove the / prefix from the path option and see if that helps?

If others hit this, check your VPN or DNS settings. In my case, OpenDNS was causing this same issue nondeterministically. I switched to another VPN and it works without issue. OpenDNS wasn't reporting anything blocked or blacklisted in the requests, but it will still causing it to fail.

One other oddity was that after getting an HTTP 500, if I then visited that same URL in the browser the results would load (somewhat slow), then I could retry the octokit request and it would work. This was 100% consistent in the behavior I was experiencing.