Skip to content

Commit 88f7da8

Browse files
TingluoHuangsirredbeard
authored andcommitted
Ignore exception during auth migration. (actions#3835)
1 parent aea61c3 commit 88f7da8

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Runner.Listener/BrokerMessageListener.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ public async Task<CreateSessionResult> CreateSessionAsync(CancellationToken toke
141141
Trace.Error("Catch exception during create session.");
142142
Trace.Error(ex);
143143

144-
if (ex is VssOAuthTokenRequestException vssOAuthEx && _credsV2.Federated is VssOAuthCredential vssOAuthCred)
144+
if (!HostContext.AllowAuthMigration &&
145+
ex is VssOAuthTokenRequestException vssOAuthEx &&
146+
_credsV2.Federated is VssOAuthCredential vssOAuthCred)
145147
{
146148
// "invalid_client" means the runner registration has been deleted from the server.
147149
if (string.Equals(vssOAuthEx.Error, "invalid_client", StringComparison.OrdinalIgnoreCase))
@@ -162,7 +164,8 @@ public async Task<CreateSessionResult> CreateSessionAsync(CancellationToken toke
162164
}
163165
}
164166

165-
if (!IsSessionCreationExceptionRetriable(ex))
167+
if (!HostContext.AllowAuthMigration &&
168+
!IsSessionCreationExceptionRetriable(ex))
166169
{
167170
_term.WriteError($"Failed to create session. {ex.Message}");
168171
if (ex is TaskAgentSessionConflictException)
@@ -283,11 +286,11 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
283286
Trace.Info("Hosted runner has been deprovisioned.");
284287
throw;
285288
}
286-
catch (AccessDeniedException e) when (e.ErrorCode == 1)
289+
catch (AccessDeniedException e) when (e.ErrorCode == 1 && !HostContext.AllowAuthMigration)
287290
{
288291
throw;
289292
}
290-
catch (RunnerNotFoundException)
293+
catch (RunnerNotFoundException) when (!HostContext.AllowAuthMigration)
291294
{
292295
throw;
293296
}
@@ -296,7 +299,8 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
296299
Trace.Error("Catch exception during get next message.");
297300
Trace.Error(ex);
298301

299-
if (!IsGetNextMessageExceptionRetriable(ex))
302+
if (!HostContext.AllowAuthMigration &&
303+
!IsGetNextMessageExceptionRetriable(ex))
300304
{
301305
throw new NonRetryableException("Get next message failed with non-retryable error.", ex);
302306
}

src/Runner.Listener/MessageListener.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
315315
Trace.Info("Hosted runner has been deprovisioned.");
316316
throw;
317317
}
318-
catch (AccessDeniedException e) when (e.ErrorCode == 1)
318+
catch (AccessDeniedException e) when (e.ErrorCode == 1 && !HostContext.AllowAuthMigration)
319319
{
320320
throw;
321321
}
322-
catch (RunnerNotFoundException)
322+
catch (RunnerNotFoundException) when (!HostContext.AllowAuthMigration)
323323
{
324324
throw;
325325
}
@@ -333,11 +333,14 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
333333
message = null;
334334

335335
// don't retry if SkipSessionRecover = true, DT service will delete agent session to stop agent from taking more jobs.
336-
if (ex is TaskAgentSessionExpiredException && !_settings.SkipSessionRecover && (await CreateSessionAsync(token) == CreateSessionResult.Success))
336+
if (!HostContext.AllowAuthMigration &&
337+
ex is TaskAgentSessionExpiredException &&
338+
!_settings.SkipSessionRecover && (await CreateSessionAsync(token) == CreateSessionResult.Success))
337339
{
338340
Trace.Info($"{nameof(TaskAgentSessionExpiredException)} received, recovered by recreate session.");
339341
}
340-
else if (!IsGetNextMessageExceptionRetriable(ex))
342+
else if (!HostContext.AllowAuthMigration &&
343+
!IsGetNextMessageExceptionRetriable(ex))
341344
{
342345
throw;
343346
}

0 commit comments

Comments
 (0)