-
Notifications
You must be signed in to change notification settings - Fork 982
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
Issue 1739: Fixing null reference exception during configuring runner with invalid repo URL or token #1741
Issue 1739: Fixing null reference exception during configuring runner with invalid repo URL or token #1741
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -634,28 +634,33 @@ private async Task<GitHubRunnerRegisterToken> GetJITRunnerTokenAsync(string gith | |
var jsonResponse = await response.Content.ReadAsStringAsync(); | ||
return StringUtil.ConvertFromJson<GitHubRunnerRegisterToken>(jsonResponse); | ||
} | ||
else if(response.StatusCode == System.Net.HttpStatusCode.NotFound) | ||
{ | ||
// It doesn't make sense to retry in this case, so just stop | ||
break; | ||
} | ||
else | ||
{ | ||
_term.WriteError($"Http response code: {response.StatusCode} from 'POST {githubApiUrl}'"); | ||
var errorResponse = await response.Content.ReadAsStringAsync(); | ||
_term.WriteError(errorResponse); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
if(response.StatusCode == System.Net.HttpStatusCode.NotFound) | ||
{ | ||
_term.WriteError("Invalid repository URL or register token"); | ||
return StringUtil.ConvertFromJson<GitHubRunnerRegisterToken>(errorResponse); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this in the new commit. |
||
} | ||
else | ||
{ | ||
// Something else bad happened, let's go to our retry logic | ||
response.EnsureSuccessStatusCode(); | ||
} | ||
} | ||
} | ||
catch(Exception ex) when (retryCount < 2) | ||
{ | ||
retryCount++; | ||
Trace.Error($"Failed to get JIT runner token -- Atempt: {retryCount}"); | ||
Trace.Error(ex); | ||
Trace.Info("Retrying in 5 seconds"); | ||
} | ||
} | ||
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5)); | ||
Trace.Info($"Retrying in {backOff.Seconds} seconds"); | ||
await Task.Delay(backOff); | ||
} | ||
return null; | ||
|
@@ -699,29 +704,33 @@ private async Task<GitHubAuthResult> GetTenantCredential(string githubUrl, strin | |
var jsonResponse = await response.Content.ReadAsStringAsync(); | ||
return StringUtil.ConvertFromJson<GitHubAuthResult>(jsonResponse); | ||
} | ||
else if(response.StatusCode == System.Net.HttpStatusCode.NotFound) | ||
{ | ||
// It doesn't make sense to retry in this case, so just stop | ||
break; | ||
} | ||
else | ||
{ | ||
_term.WriteError($"Http response code: {response.StatusCode} from 'POST {githubApiUrl}'"); | ||
var errorResponse = await response.Content.ReadAsStringAsync(); | ||
_term.WriteError(errorResponse); | ||
// Something else bad happened, let's go to our retry logic | ||
response.EnsureSuccessStatusCode(); | ||
|
||
if(response.StatusCode == System.Net.HttpStatusCode.NotFound) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above! |
||
{ | ||
_term.WriteError("Invalid repository URL or register token"); | ||
return StringUtil.ConvertFromJson<GitHubAuthResult>(errorResponse); | ||
} | ||
else | ||
{ | ||
// Something else bad happened, let's go to our retry logic | ||
response.EnsureSuccessStatusCode(); | ||
} | ||
} | ||
} | ||
catch(Exception ex) when (retryCount < 2) | ||
{ | ||
retryCount++; | ||
Trace.Error($"Failed to get tenant credentials -- Atempt: {retryCount}"); | ||
Trace.Error(ex); | ||
Trace.Info("Retrying in 5 seconds"); | ||
} | ||
} | ||
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5)); | ||
Trace.Info($"Retrying in {backOff.Seconds} seconds"); | ||
await Task.Delay(backOff); | ||
} | ||
return null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just try storing the response code and using that to determine if we should throw or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to add others to this not retry list, and looking at the response code is the easiest way to do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just won't trace delay time there, because it's randomly determined outside of catch.