Skip to content
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

GitHub API socket hang up #25

Open
1 task done
bmaupin opened this issue Sep 5, 2024 · 1 comment
Open
1 task done

GitHub API socket hang up #25

bmaupin opened this issue Sep 5, 2024 · 1 comment

Comments

@bmaupin
Copy link
Owner

bmaupin commented Sep 5, 2024

I got this error:

Debug: Populating scores for 2019-07-01
Successfully populated 548 scores
Error: socket hang up (ECONNRESET)
    at ClientRequest.<anonymous> (/home/bmaupin/Dropbox/workspace/personal/langtrends-data/src/GitHub.ts:161:16)
    at ClientRequest.emit (node:events:518:28)
    at ClientRequest.emit (node:domain:488:12)
    at TLSSocket.socketOnEnd (node:_http_client:519:9)
    at TLSSocket.emit (node:events:530:35)
    at TLSSocket.emit (node:domain:488:12)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

Could it be related to nodejs/node#47130 ?

According to that issue, it's introduced in Node 20, which sets keep alive by default for HTTPS requests. The underlying cause is an issue with the HTTP/1.1 spec itself, so can't be fixed.

Seems like possible workarounds are:

  • Use another HTTP client that doesn't have this issue, such as https://github.com/nodejs/undici

  • Disable keepalive, e.g.

    const agent = new https.Agent({ keepAlive: false });
    
    const options = {
      headers: {
        Authorization: `bearer ${this.apiKey}`,
        'User-Agent': 'node.js',
      },
      hostname: optionsUrl.hostname,
      method: 'POST',
      path: optionsUrl.pathname,
      agent: agent,  // Use custom agent
    };
  • Or add retry logic

        request.on('error', (err: NodeJS.ErrnoException) => {
          if (err.code === 'ECONNRESET') {
            // do something with retryOnError?
    

This happened when updating all scores after adding new languages, which results in a lot of API calls. So in theory this would be less likely to happen just for the normal monthly scores update.

To do:

  • Re-run score update after adding new languages to see if the problem occurs again
@bmaupin
Copy link
Owner Author

bmaupin commented Sep 5, 2024

Running it a second time, no issues. I'll leave this open for now just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant