octokit.net icon indicating copy to clipboard operation
octokit.net copied to clipboard

a Server Error has occurred

Open bobbytreed opened this issue 6 years ago • 16 comments

Exception : System.AggregateException: One or more errors occurred. ---> Octokit.ApiException: Server Error at Octokit.Connection.HandleErrors(IResponse response) at Octokit.Connection.<RunRequest>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.Connection.<Run>d__571.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.Internal.ReadOnlyPagedCollection1.<GetNextPage>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.ApiPagination.<GetAllPages>d__01.MoveNext() --- End of inner exception stack trace --- ---> (Inner Exception #0) Octokit.ApiException: Server Error at Octokit.Connection.HandleErrors(IResponse response) at Octokit.Connection.<RunRequest>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.Connection.<Run>d__571.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.Internal.ReadOnlyPagedCollection1.<GetNextPage>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.ApiPagination.<GetAllPages>d__01.MoveNext() { "message": "Server Error" }

$options = New-Object octokit.apioptions
$options.PageSize = 100

$issueRequest = New-Object Octokit.RepositoryIssueRequest
$issueRequest.State = "All"
$issueRequest.Filter = "All"

$issues = gitHubClient.Issue.GetAllForRepository($repo.Id, $issueRequest, $options)

// $Repo is defined elsewhere and is valid

bobbytreed avatar Sep 30 '19 20:09 bobbytreed

Hey @bobbytreed, thanks for reporting this issue.

I've tried replicating this issue on a few different repositories but I've not been able to get the same error response as you've posted.

If this is reproducible on a public repository that you could provide us, that'll greatly help to speed up reproducing this issue.

Cheers, Henrik

hnrkndrssn avatar Oct 01 '19 10:10 hnrkndrssn

Sure. https://github.com/MicrosoftDocs/azure-docs

bobbytreed avatar Oct 01 '19 17:10 bobbytreed

I wrote a test (same as sample above) to replicate this issue. First run it failed with the same Server Error response, so I ran it again in debug mode to see if I get some more details about why it failed but the test passed... 😕

[IntegrationTest]
public async Task ServerErrorBugTest()
{
    var options = new ApiOptions
    {
        PageSize = 100
    };

    var issueRequest = new RepositoryIssueRequest
    {
        Filter = IssueFilter.All,
        State = ItemStateFilter.All
    };

    var repoIssues = await _issuesClient.GetAllForRepository("MicrosoftDocs", "azure-docs", issueRequest, options);
    Assert.NotNull(repoIssues);
}

hnrkndrssn avatar Oct 04 '19 09:10 hnrkndrssn

I'm still having the issue, so I'm not sure what to do.

bobbytreed avatar Oct 04 '19 09:10 bobbytreed

Ha! Reproduced the error after rebooting my machine 🙄

It doesn't really give any more details though... 😢

image

hnrkndrssn avatar Oct 04 '19 10:10 hnrkndrssn

@hnrkndrssn what's interesting about the response is that it appears to have a valid X-GitHub-Request-Id, meaning it did reach the GitHub infrastructure, but it also has a status code of 502 Bad Gateway. Not quite clear what it means, but the docs just suggest here that an "invalid response" was received from the GitHub infrastructure:

The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.

As this feels like something that we can't address in the client library, I'm inclined to close it if we provide enough details in the error that someone can provide the information to GitHub Support to help resolve their problem.

shiftkey avatar Nov 18 '19 11:11 shiftkey

Aye, it's an odd one... I'd be happy to do a PR to provide some better error handling for this scenario

hnrkndrssn avatar Nov 18 '19 11:11 hnrkndrssn

I'd be happy to do a PR to provide some better error handling for this scenario

I'd love to review any improvements or ideas you have here

shiftkey avatar Nov 18 '19 11:11 shiftkey

Oddly enough, hitting this URL (which is the resulting URI in octokit.net, but without any accept headers) sometimes returns the same Server error response but other times it successfully returns the actual results... 😕

image

hnrkndrssn avatar Nov 19 '19 07:11 hnrkndrssn

I had an idea about how we could improve how we get error messages that we return for known error responses from the GitHub API but it might be over-engineering things so I'll mention it here first before going any further.

In another product (that shall remain unnamed 😃) I'm involved in, we have an ExceptionKnowledgeBase that contains a list of "rules" that match different type of exceptions and accompanying summary/help text and links to docs.

ExceptionKnowledgeBase.AddRule(r => 
    r.ExceptionIs<SomeException>(ex => 
        ex.ErrorCode == "some_errorcode" && ex.Message.StartsWith("Some text")
    )
    .EntrySummaryIs("Some helpful summary")
    .EntryHelpTextIs("Some helpful help text")
    .EntryHelpLinkIs("https://some.link.to/docs")
);

and then you use it like

if (ExceptionKnowledgeBase.TryInterpret(ex, out entry))
{
    error.ErrorMessage = entry.Summary;
    error.HelpText = entry.HelpText;
    error.HelpLink = entry.HelpLink;
}

We'd obviously need to tweak the functionality slightly for octokit.net to work in the same way as we currently handle known error responses from the GitHub API, e.g.

https://github.com/octokit/octokit.net/blob/5ffc96995faa4ca0137521e628db2b7c862073b0/Octokit/Http/Connection.cs#L645-L653

Otherwise, we can just use another entry to the _httpExceptionMap in a similar way as we do for HttpStatusCode.Forbidden that calls the GetExceptionForForbidden and checks the body of the response for certain key phrases.

hnrkndrssn avatar Nov 19 '19 12:11 hnrkndrssn

@hnrkndrssn if you can get me a recent X-GitHub-Request-Id I can dig into why these might be failing intermittently.

As for the proposed changes, I'm not 100% clear on what the resolution would be in this situation. I think, if we had problems that could be addressed in a self-service way, this format might help. But given the unclear and intermittent nature of this, for now I think we should provide more context or a more relevant exception type for BadGateway.

shiftkey avatar Nov 19 '19 13:11 shiftkey

Yea, it certainly feels like following the same format as we do for other HttpStatusCodes is a better solution for now.

I just re-ran my test that fails consistently and here is the X-GitHub-Request-Id that was returned in the response D2F8:43F5:F2E02:119B8E:5DD3EE56

And here is one that failed in the browser D31E:1DDE:106BF8:12DD33:5DD3EFB4 and then succeeded in the browser D31E:1DDE:106F65:12E1CA:5DD3EFD8

hnrkndrssn avatar Nov 19 '19 13:11 hnrkndrssn

Good Morning All, Sorry for being absent, but good to see the conversation continued. I'm getting this same error again today on another benign call.

currentBranches = await _client.Git.Reference.GetAll(From.owner, From.name);

Here is the stack trace

at Octokit.Connection.HandleErrors(IResponse response) in /home/runner/work/octokit.net/octokit.net/Octokit/Http/Connection.cs:line 707 at Octokit.Connection.<RunRequest>d__60.MoveNext() in /home/runner/work/octokit.net/octokit.net/Octokit/Http/Connection.cs:line 682 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.Connection.<Run>d__591.MoveNext() in /home/runner/work/octokit.net/octokit.net/Octokit/Http/Connection.cs:line 666 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.ApiConnection.<GetPage>d__431.MoveNext() in /home/runner/work/octokit.net/octokit.net/Octokit/Http/ApiConnection.cs:line 628 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.ApiConnection.<>c__DisplayClass18_01.<<GetAll>b__0>d.MoveNext() in /home/runner/work/octokit.net/octokit.net/Octokit/Http/ApiConnection.cs:line 212 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiPagination.<GetAllPages>d__01.MoveNext() in /home/runner/work/octokit.net/octokit.net/Octokit/Clients/ApiPagination.cs:line 37 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at DocIndex.Service.Helpers.PullRequestHelper.<CreateForkBranchIfNotExists>d__38.MoveNext() in C:\Users\robreed\source\docindex\src\service\Helpers\GitHubHelpers.cs:line 72 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at DocIndex.Service.Helpers.PullRequestHelper.<StartPullRequest>d__40.MoveNext() in C:\Users\robreed\source\docindex\src\service\Helpers\GitHubHelpers.cs:line 118

Oddly, the request works when queried against my own repos, but not against other repos for which I have authorized my saml token, etc.

bobbytreed avatar May 17 '21 12:05 bobbytreed

Even more oddly, it works in all cases when invoked from PowerShell, but not from C#. I tested with .50 in C# and it failed, so I have a PS GitHubClient instance in my profile using the .32 version DLL (don't update it often). The Git.Reference.Get call works from there to any repo. I tried downgrading to .32 in C#, but it did not work.

bobbytreed avatar May 17 '21 12:05 bobbytreed

Still Getting this error.

┌[ GLaDOS ] [  main ≣ ~3 -0 ! ] └[~\source\docindex]> $prs = $gitHubClient.PullRequest.GetAllForRepository("MicrosoftDocs", "azure-docs-pr", $request) ┌[ GLaDOS ] [  main ≣ ~3 -0 ! ] └[~\source\docindex]> $prs

Result : Id : 671 Exception : System.AggregateException: One or more errors occurred. ---> Octokit.ApiException: Server Error at Octokit.Connection.HandleErrors(IResponse response) at Octokit.Connection.<RunRequest>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.Connection.<Run>d__571.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiConnection.<GetPage>d__421.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiConnection.<>c__DisplayClass17_01.<<GetAll>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiPagination.<GetAllPages>d__01.MoveNext() --- End of inner exception stack trace --- ---> (Inner Exception #0) Octokit.ApiException: Server Error at Octokit.Connection.HandleErrors(IResponse response) at Octokit.Connection.<RunRequest>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.Connection.<Run>d__571.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiConnection.<GetPage>d__421.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiConnection.<>c__DisplayClass17_01.<<GetAll>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiPagination.<GetAllPages>d__01.MoveNext() { "message": "Server Error" } <---

Happens in PowerShell and C# now, in GraphQL and normal. The Repository has 164k pull requests, could that be an issue?

Not understanding how commands that have worked for years could start failing.

bobbytreed avatar Jun 22 '21 13:06 bobbytreed

C# Stack Trace (.50)

at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at Octokit.GraphQL.Connection.<Run>d__25.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Octokit.GraphQL.Core.SimpleQuery1.Runner.<RunPage>d__10.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Octokit.GraphQL.ConnectionExtensions.<Run>d__21.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at DocIndex.Service.Helpers.GitHubHelper.<GetPullRequestsGraphQL>d__27.MoveNext() in

bobbytreed avatar Jun 22 '21 13:06 bobbytreed

I ran into this same error today and don't seem to have a workaround. Any thoughts on why we are getting this?

jongio avatar Mar 03 '23 18:03 jongio

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

github-actions[bot] avatar Nov 29 '23 01:11 github-actions[bot]