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

[BUG] GiHub GraphQL api got http 502 error #67

Closed
kerthcet opened this issue Oct 24, 2021 · 14 comments · Fixed by #68
Closed

[BUG] GiHub GraphQL api got http 502 error #67

kerthcet opened this issue Oct 24, 2021 · 14 comments · Fixed by #68

Comments

@kerthcet
Copy link
Contributor

Describe the bug
several cards' svg can not generated successfully.

Expected behavior
All cards should be generated successfully.

Errors

generate
Error when creating ProfileDetailsCard 
Error: Request failed with status code 502
    at createError (/home/runner/work/_actions/vn7n24fzkq/github-profile-summary-cards/release/dist/index.js:9143:15)
    at settle (/home/runner/work/_actions/vn7n24fzkq/github-profile-summary-cards/release/dist/index.js:9402:12)
    at IncomingMessage.handleStreamEnd (/home/runner/work/_actions/vn7n24fzkq/github-profile-summary-cards/release/dist/index.js:8529:11)
    at IncomingMessage.emit (events.js:215:7)
    at endReadableNT (_stream_readable.js:1184:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
```
@vn7n24fzkq
Copy link
Owner

vn7n24fzkq commented Oct 25, 2021

That's odd.

502 is the bad gateway of HTTP code but we are using GraphQL here.

@d12frosted
Copy link
Contributor

d12frosted commented Oct 26, 2021

Hey, I actually got the same error. You can find it here: https://github.com/d12frosted/d12frosted/actions/runs/1384168586

Let me know if you need any extra information to debug this.

BTW, graphql is over http, so http status codes apply here as well.

@d12frosted
Copy link
Contributor

Can reproduce locally. Added some logs:

{
  data: null,
  errors: [
    {
      message: 'Something went wrong while executing your query. This may be the result of a timeout, or it could be a GitHub bug. Please include `F2F7:0D5E:BE2D83:C2E128:6177935E` when reporting this issue.'
    }
  ]
}
502
{
  server: 'GitHub.com',
  date: 'Tue, 26 Oct 2021 05:34:32 GMT',
  'content-type': 'application/json',
  'transfer-encoding': 'chunked',
  'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
  'access-control-allow-origin': '*',
  vary: 'Accept-Encoding, Accept, X-Requested-With',
  'x-github-request-id': 'F2F7:0D5E:BE2D83:C2E128:6177935E',
  connection: 'close'
}
{
  url: 'https://api.github.com/graphql',
  method: 'post',
  data: '{"query":"\\n      query UserDetails($login: String!) {\\n        user(login: $login) {\\n            id\\n            name\\n            email\\n            createdAt\\n            twitterUsername\\n            company\\n            location\\n            websiteUrl\\n            repositories(first: 100,privacy:PUBLIC, isFork: false, ownerAffiliations: OWNER, orderBy: {direction: DESC, field: STARGAZERS}) {\\n              totalCount\\n              nodes {\\n                stargazers {\\n                  totalCount\\n                }\\n              }\\n            }\\n            contributionsCollection {\\n                contributionCalendar {\\n                    weeks {\\n                        contributionDays {\\n                            contributionCount\\n                            date\\n                        }\\n                    }\\n                }\\n                contributionYears\\n            }\\n            repositoriesContributedTo(first: 1,includeUserRepositories:true, privacy:PUBLIC, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {\\n                totalCount\\n            }\\n            pullRequests(first: 1) {\\n                totalCount\\n            }\\n            issues(first: 1) {\\n                totalCount\\n            }\\n        }\\n      }\\n\\n      ","variables":{"login":"d12frosted"}}',
  headers: {
    Accept: 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    Authorization: 'bearer ghp_TOKEN',
    'User-Agent': 'axios/0.21.4',
    'Content-Length': 1336
  },
  transformRequest: [ [Function: transformRequest] ],
  transformResponse: [ [Function: transformResponse] ],
  timeout: 0,
  adapter: [Function: httpAdapter],
  xsrfCookieName: 'XSRF-TOKEN',
  xsrfHeaderName: 'X-XSRF-TOKEN',
  maxContentLength: -1,
  maxBodyLength: -1,
  validateStatus: [Function: validateStatus],
  transitional: {
    silentJSONParsing: true,
    forcedJSONParsing: true,
    clarifyTimeoutError: false
  }
}

@d12frosted
Copy link
Contributor

d12frosted commented Oct 26, 2021

What works - splitting this huge query into several. I tried the following:

const fetcher1 = (token, variables) => {
    // contain private need token permission
    // contributionsCollection default to a year ago
    return request(
        {
            Authorization: `bearer ${token}`,
        },
        {
            query: `
      query UserDetails($login: String!) {
        user(login: $login) {
            id
            name
            email
            createdAt
            twitterUsername
            company
            location
            websiteUrl
            repositories(first: 100,privacy:PUBLIC, isFork: false, ownerAffiliations: OWNER, orderBy: {direction: DESC, field: STARGAZERS}) {
              totalCount
              nodes {
                stargazers {
                  totalCount
                }
              }
            }
        }
      }

      `,
            variables,
        }
    );
};

const fetcher2 = (token, variables) => {
    // contain private need token permission
    // contributionsCollection default to a year ago
    return request(
        {
            Authorization: `bearer ${token}`,
        },
        {
            query: `
      query UserDetails($login: String!) {
        user(login: $login) {
            contributionsCollection {
                contributionCalendar {
                    weeks {
                        contributionDays {
                            contributionCount
                            date
                        }
                    }
                }
                contributionYears
            }
        }
      }

      `,
            variables,
        }
    );
};

const fetcher3 = (token, variables) => {
    // contain private need token permission
    // contributionsCollection default to a year ago
    return request(
        {
            Authorization: `bearer ${token}`,
        },
        {
            query: `
      query UserDetails($login: String!) {
        user(login: $login) {
            repositoriesContributedTo(first: 1,includeUserRepositories:true, privacy:PUBLIC, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
                totalCount
            }
            pullRequests(first: 1) {
                totalCount
            }
            issues(first: 1) {
                totalCount
            }
        }
      }

      `,
            variables,
        }
    );
};

And then combining everything:

const user = { ...res1.data.data.user, ...res2.data.data.user, ...res3.data.data.user };

And that worked for ProfileDetailsCard. The same with StatsCard.

If you wish, I can send a PR fixing both of them.

@vn7n24fzkq
Copy link
Owner

Hey, I actually got the same error. You can find it here: https://github.com/d12frosted/d12frosted/actions/runs/1384168586

Let me know if you need any extra information to debug this.

BTW, graphql is over http, so http status codes apply here as well.

Yeah, I know, I mean we do not do any change here so it is odd to that we suddenly get 502 error. 🤔

@vn7n24fzkq vn7n24fzkq changed the title [BUG] [BUG] GiHub GraphQL api got http 502 error Oct 26, 2021
@vn7n24fzkq
Copy link
Owner

@d12frosted Thanks!!

If you resend the request would it still respond with a 502 error?

Cuz I found something similar here magit/ghub#83
And here is the limitations of APIv4 https://docs.github.com/en/graphql/overview/resource-limitations

If we ensure the problem is about request limitations then we will need this PR.

@d12frosted
Copy link
Contributor

Even by splitting request into multiple I still run into 502 time to time. So I added some retries and now it's more stable.

In addition, I usually experienced 502 more often during StatsCard generation. So it got me thinking, maybe profile should not be fetched twice?

@vn7n24fzkq
Copy link
Owner

Maybe we can add some retries and don't need to split the request?

For locally and GitHub Action usage we don't need to fetch twice, but to deploy on Vercel we need it because every request is independent of others.

@vn7n24fzkq
Copy link
Owner

Maybe it is a GitHub upstream service issue.🤔

@d12frosted
Copy link
Contributor

Maybe we can add some retries and don't need to split the request?

This is what I say :) I added retries and everything become better :) If you wish, I can send a PR with retries only.

@vn7n24fzkq
Copy link
Owner

vn7n24fzkq commented Oct 26, 2021

Maybe we can add some retries and don't need to split the request?

This is what I say :) I added retries and everything become better :) If you wish, I can send a PR with retries only.

Yes, please. 😄
I will check and merge it as a hotfix a few hours later.

@kerthcet
Copy link
Contributor Author

glad to hear that your guys have found the solutation🎉

@vn7n24fzkq
Copy link
Owner

It is released now, thanks for your hard work. 🎉

@xgjiang
Copy link

xgjiang commented Jul 24, 2023

In my case, sometimes it is because the result of the query is too large (I reduce the number of issues to be returned from 100 to 10, and it works).

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

Successfully merging a pull request may close this issue.

4 participants