-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Sps/token migration tweak, ActionResult casing. #462
Changes from all commits
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 |
---|---|---|
|
@@ -164,9 +164,30 @@ public async Task<Boolean> CreateSessionAsync(CancellationToken token) | |
} | ||
} | ||
|
||
if (ex is TaskAgentSessionConflictException) | ||
{ | ||
try | ||
{ | ||
var newCred = await GetNewOAuthAuthorizationSetting(token, true); | ||
if (newCred != null) | ||
{ | ||
await _runnerServer.ConnectAsync(new Uri(_settings.ServerUrl), newCred); | ||
Trace.Info("Updated connection to use migrated credential for next CreateSession call."); | ||
_useMigratedCredentials = true; | ||
_authorizationUrlMigrationBackgroundTask = null; | ||
_needToCheckAuthorizationUrlUpdate = false; | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Trace.Error("Fail to refresh connection with new authorization url."); | ||
Trace.Error(e); | ||
} | ||
} | ||
|
||
if (!IsSessionCreationExceptionRetriable(ex)) | ||
{ | ||
if (_useMigratedCredentials) | ||
if (_useMigratedCredentials && !(ex is TaskAgentSessionConflictException)) | ||
{ | ||
// migrated credentials might cause lose permission during permission check, | ||
// we will force to use original credential and try again | ||
|
@@ -516,14 +537,11 @@ ex is AccessDeniedException || | |
} | ||
} | ||
|
||
private async Task<VssCredentials> GetNewOAuthAuthorizationSetting(CancellationToken token) | ||
private async Task<VssCredentials> GetNewOAuthAuthorizationSetting(CancellationToken token, bool adhoc = false) | ||
{ | ||
Trace.Info("Start checking oauth authorization url update."); | ||
while (true) | ||
{ | ||
var backoff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(45)); | ||
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. move the sleep to the end of the iteration, since most runner has finished migration. there are a small number of runners connected to the server once a while only for a few minutes, so the delay is too long for them. |
||
await HostContext.Delay(backoff, token); | ||
|
||
try | ||
{ | ||
var migratedAuthorizationUrl = await _runnerServer.GetRunnerAuthUrlAsync(_settings.PoolId, _settings.AgentId); | ||
|
@@ -538,7 +556,14 @@ private async Task<VssCredentials> GetNewOAuthAuthorizationSetting(CancellationT | |
{ | ||
// We don't need to update credentials. | ||
Trace.Info("No needs to update authorization url"); | ||
await Task.Delay(TimeSpan.FromMilliseconds(-1), token); | ||
if (adhoc) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
await Task.Delay(TimeSpan.FromMilliseconds(-1), token); | ||
} | ||
} | ||
|
||
var keyManager = HostContext.GetService<IRSAKeyManager>(); | ||
|
@@ -572,7 +597,7 @@ private async Task<VssCredentials> GetNewOAuthAuthorizationSetting(CancellationT | |
Trace.Verbose("No authorization url updates"); | ||
} | ||
} | ||
catch (Exception ex) | ||
catch (Exception ex) when (!token.IsCancellationRequested) | ||
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. don't report migration error when user ctrl-c the runner. |
||
{ | ||
Trace.Error("Fail to get/test new authorization url."); | ||
Trace.Error(ex); | ||
|
@@ -588,6 +613,16 @@ private async Task<VssCredentials> GetNewOAuthAuthorizationSetting(CancellationT | |
Trace.Error(e); | ||
} | ||
} | ||
|
||
if (adhoc) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
var backoff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(45)); | ||
await HostContext.Delay(backoff, token); | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ public ActionResult? Status | |
} | ||
set | ||
{ | ||
this["status"] = new StringContextData(value.ToString()); | ||
this["status"] = new StringContextData(value.ToString().ToLowerInvariant()); | ||
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. change to lower case to match GitHub check result |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,19 +59,19 @@ public void SetOutput( | |
public void SetConclusion( | ||
string scopeName, | ||
string stepName, | ||
string conclusion) | ||
ActionResult conclusion) | ||
{ | ||
var step = GetStep(scopeName, stepName); | ||
step["conclusion"] = new StringContextData(conclusion); | ||
step["conclusion"] = new StringContextData(conclusion.ToString().ToLowerInvariant()); | ||
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. change to lower case to match GitHub check result |
||
} | ||
|
||
public void SetOutcome( | ||
string scopeName, | ||
string stepName, | ||
string outcome) | ||
ActionResult outcome) | ||
{ | ||
var step = GetStep(scopeName, stepName); | ||
step["outcome"] = new StringContextData(outcome); | ||
step["outcome"] = new StringContextData(outcome.ToString().ToLowerInvariant()); | ||
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. change to lower case to match GitHub check result |
||
} | ||
|
||
private DictionaryContextData GetStep(string scopeName, string stepName) | ||
|
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.
try migration even on session conflict since there are a small number of runners (might be orchestrated by some auto-provision/scaling tools) hitting session conflict all the time.