google / go-github

Go library for accessing the GitHub v3 API
https://pkg.go.dev/github.com/google/go-github/v66/github
BSD 3-Clause "New" or "Revised" License
10.45k stars 2.06k forks source link

Context Deadline Exceeds when Deploying to Cloud Run #2097

Closed ex0dus-0x closed 3 years ago

ex0dus-0x commented 3 years ago

I'm deploying a GitHub application that uses go-github through palantir/go-githubapp. The application handles PR events, and creates a Check Run for analyzing changed files in the commit. I've built and uploaded the container image to the registry, and deployed a Cloud Run app.

While everything works nicely on a local host, I keep getting the following error any time the app makes an outbound request to GitHub API for instantiating a Check Run:

Post "https://api.github.com/repos/ex0dus-0x/pkg-bkdoor-poc/check-runs": could not refresh installation id 19058859's token: could not get access_tokens from GitHub API for installation ID 19058859: context deadline exceeded (Client.Timeout exceeded while awaiting headers)

The corresponding code:

    // instantiate authenticated client and context
    installationID := githubapp.GetInstallationIDFromEvent(&event)
    ctx, logger := githubapp.PreparePRContext(ctx, installationID, repo, prNum)
    client, err := h.NewInstallationClient(installationID)
    if err != nil {
        return errors.Wrap(err, "cannot instantiate client for interaction")
    }

    logger.Debug().Msgf("Creating new Check Run")
    name := "Scan"
    run, _, err := client.Checks.CreateCheckRun(ctx, author, repoName,
        github.CreateCheckRunOptions{
            Name:    name,
            HeadSHA: pr.GetHead().GetSHA(),
        },
    )
        if err != nil {
            return err
        }

I've tried to manually update the deadline to something longer, but that didn't seem to work. Any ideas why this is happening and how to fix?

gmlewis commented 3 years ago

My first guess is that the local transport is authenticating differently from the other environment.

Have you asked on the https://github.com/palantir/go-githubapp repo where they might have a bit more context and/or experience with this scenario?

ex0dus-0x commented 3 years ago

Yup, turns out configurations on the cloud side and how it worked with their end was the issue, not the GitHub API call itself. Thanks!