gh-gei icon indicating copy to clipboard operation
gh-gei copied to clipboard

Retry on retrieving team slug after creation

Open dylan-smith opened this issue 3 years ago • 2 comments

@mickeygousset was testing out a migration and create-team command failed. It appears it called an API to create a new team, and got back a success. Then tried to call an API to get the team details, and GitHub said no teams exist.

This feels like some kind of race condition in the GH API, and I suspect if we waited a few seconds then tried to retrieve the team again it would work.

Our existing retry logic didn't kick in here, because the call to get the team details didn't fail, it succeeded it just didn't include the data in the response (the new team) that we expected it to.

[11:34 AM] [DEBUG] HTTP GET: https://raw.githubusercontent.com/github/gh-gei/main/LATEST-VERSION.txt
[11:34 AM] [DEBUG] RESPONSE (OK): v0.26

[11:34 AM] [INFO] You are running the latest version of the ado2gh CLI [v0.26]
[11:34 AM] [INFO] Creating GitHub team...
[11:34 AM] [INFO] GITHUB ORG: mickey-test-migrations
[11:34 AM] [INFO] TEAM NAME: MyShuttle-Maintainers
[11:34 AM] [INFO] IDP GROUP: MyShuttle-Maintainers
[11:34 AM] [DEBUG] HTTP GET: https://api.github.com/orgs/mickey-test-migrations/teams
[11:34 AM] [DEBUG] GITHUB REQUEST ID: E454:659E:BD4178:182F6A6:6329EB9E
[11:34 AM] [DEBUG] RESPONSE (OK): []
[11:34 AM] [DEBUG] HTTP POST: https://api.github.com/orgs/mickey-test-migrations/teams
[11:34 AM] [DEBUG] HTTP BODY: {"name":"MyShuttle-Maintainers","privacy":"closed"}
[11:34 AM] [DEBUG] GITHUB REQUEST ID: E454:659E:BD41D8:182F76A:6329EB9F
[11:34 AM] [DEBUG] RESPONSE (Created): {"name":"MyShuttle-Maintainers","id":6656283,"node_id":"T_kwDOBsS6Ms4AZZEb","slug":"myshuttle-maintainers","description":null,"privacy":"closed","url":"https://api.github.com/organizations/113556018/team/6656283","html_url":"https://github.com/orgs/mickey-test-migrations/teams/myshuttle-maintainers","members_url":"https://api.github.com/organizations/113556018/team/6656283/members{/member}","repositories_url":"https://api.github.com/organizations/113556018/team/6656283/repos","permission":"pull","parent":null,"created_at":"2022-09-20T16:34:39Z","updated_at":"2022-09-20T16:34:39Z","members_count":1,"repos_count":0,"organization":{"login":"mickey-test-migrations","id":113556018,"node_id":"O_kgDOBsS6Mg","url":"https://api.github.com/orgs/mickey-test-migrations","repos_url":"https://api.github.com/orgs/mickey-test-migrations/repos","events_url":"https://api.github.com/orgs/mickey-test-migrations/events","hooks_url":"https://api.github.com/orgs/mickey-test-migrations/hooks","issues_url":"https://api.github.com/orgs/mickey-test-migrations/issues","members_url":"https://api.github.com/orgs/mickey-test-migrations/members{/member}","public_members_url":"https://api.github.com/orgs/mickey-test-migrations/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/113556018?v=4","description":null,"is_verified":false,"has_organization_projects":true,"has_repository_projects":true,"public_repos":0,"public_gists":0,"followers":0,"following":0,"html_url":"https://github.com/mickey-test-migrations","created_at":"2022-09-14T20:35:08Z","updated_at":"2022-09-19T20:05:37Z","type":"Organization"}}
[11:34 AM] [INFO] Successfully created team
[11:34 AM] [DEBUG] HTTP GET: https://api.github.com/orgs/mickey-test-migrations/teams
[11:34 AM] [DEBUG] GITHUB REQUEST ID: E454:659E:BD42F1:182F9A4:6329EBA0
[11:34 AM] [DEBUG] RESPONSE (OK): []
[11:34 AM] [ERROR] System.InvalidOperationException: Source sequence doesn't contain any elements.
   at System.Linq.AsyncEnumerable.<SingleAsync>g__Core|335_0[TSource](IAsyncEnumerable`1 source, Func`2 predicate, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Single.cs:line 101
   at OctoshiftCLI.GithubApi.GetTeamSlug(String org, String teamName)
   at OctoshiftCLI.Commands.CreateTeamCommandBase.Handle(String githubOrg, String teamName, String idpGroup, String githubPat, Boolean verbose)
   at System.CommandLine.Invocation.CommandHandler.GetExitCodeAsync(Object value, InvocationContext context)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

dylan-smith avatar Sep 20 '22 18:09 dylan-smith

just saw this happen in an integration test too: https://github.com/github/gh-gei/actions/runs/3094609981/jobs/5008170389#step:19:411

dylan-smith avatar Sep 21 '22 02:09 dylan-smith

Happened again: https://github.com/github/gh-gei/actions/runs/3109938217/jobs/5040634508#step:19:2761

dylan-smith avatar Sep 23 '22 02:09 dylan-smith

Happened again: https://github.com/github/gh-gei/actions/runs/4300949161/jobs/7497645171#step:18:2702

dylan-smith avatar Mar 02 '23 15:03 dylan-smith

happened again: https://github.com/github/gh-gei/actions/runs/4503472686/jobs/7926764386#step:17:284

dylan-smith avatar Mar 23 '23 18:03 dylan-smith

I'm sold! Putting this near the top of the backlog so we never have to look at this again 😂

timrogers avatar Mar 23 '23 19:03 timrogers