diff --git a/src/Runner.Common/BrokerServer.cs b/src/Runner.Common/BrokerServer.cs index 4c612e9615e..7ca4713f7bd 100644 --- a/src/Runner.Common/BrokerServer.cs +++ b/src/Runner.Common/BrokerServer.cs @@ -7,6 +7,7 @@ using GitHub.DistributedTask.WebApi; using GitHub.Runner.Sdk; using GitHub.Services.Common; +using GitHub.Services.WebApi; using Sdk.RSWebApi.Contracts; using Sdk.WebApi.WebApi.RawClient; @@ -92,7 +93,7 @@ public Task ForceRefreshConnection(VssCredentials credentials) public bool ShouldRetryException(Exception ex) { - if (ex is AccessDeniedException ade) + if (ex is AccessDeniedException || ex is RunnerNotFoundException) { return false; } diff --git a/src/Runner.Listener/BrokerMessageListener.cs b/src/Runner.Listener/BrokerMessageListener.cs index 81ef5402a84..89899181146 100644 --- a/src/Runner.Listener/BrokerMessageListener.cs +++ b/src/Runner.Listener/BrokerMessageListener.cs @@ -11,9 +11,10 @@ using GitHub.Runner.Common; using GitHub.Runner.Listener.Configuration; using GitHub.Runner.Sdk; -using GitHub.Services.Common; using GitHub.Runner.Common.Util; +using GitHub.Services.Common; using GitHub.Services.OAuth; +using GitHub.Services.WebApi; namespace GitHub.Runner.Listener { @@ -241,6 +242,10 @@ public async Task GetNextMessageAsync(CancellationToken token) { throw; } + catch (RunnerNotFoundException) + { + throw; + } catch (Exception ex) { Trace.Error("Catch exception during get next message."); @@ -324,6 +329,7 @@ private bool IsGetNextMessageExceptionRetriable(Exception ex) ex is TaskAgentPoolNotFoundException || ex is TaskAgentSessionExpiredException || ex is AccessDeniedException || + ex is RunnerNotFoundException || ex is VssUnauthorizedException) { Trace.Info($"Non-retriable exception: {ex.Message}"); diff --git a/src/Runner.Listener/MessageListener.cs b/src/Runner.Listener/MessageListener.cs index 6a5c9368edc..9ea44b3f5b0 100644 --- a/src/Runner.Listener/MessageListener.cs +++ b/src/Runner.Listener/MessageListener.cs @@ -308,6 +308,10 @@ public async Task GetNextMessageAsync(CancellationToken token) { throw; } + catch (RunnerNotFoundException) + { + throw; + } catch (Exception ex) { Trace.Error("Catch exception during get next message."); @@ -457,6 +461,7 @@ private bool IsGetNextMessageExceptionRetriable(Exception ex) ex is TaskAgentPoolNotFoundException || ex is TaskAgentSessionExpiredException || ex is AccessDeniedException || + ex is RunnerNotFoundException || ex is VssUnauthorizedException) { Trace.Info($"Non-retriable exception: {ex.Message}"); diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index a6bdce62ce8..80852d32c4d 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using GitHub.DistributedTask.WebApi; +using GitHub.Services.WebApi; namespace GitHub.Runner.Listener { @@ -144,6 +145,12 @@ private async static Task MainAsync(IHostContext context, string[] args) trace.Error(e); return Constants.Runner.ReturnCode.TerminatedError; } + catch (RunnerNotFoundException e) + { + terminal.WriteError($"An error occurred: {e.Message}"); + trace.Error(e); + return Constants.Runner.ReturnCode.TerminatedError; + } catch (Exception e) { terminal.WriteError($"An error occurred: {e.Message}"); diff --git a/src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs b/src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs index 15c423017db..12022a83979 100644 --- a/src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs +++ b/src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs @@ -5,6 +5,7 @@ namespace GitHub.Actions.RunService.WebApi [DataContract] public class BrokerErrorKind { + public const string RunnerNotFound = "RunnerNotFound"; public const string RunnerVersionTooOld = "RunnerVersionTooOld"; } } diff --git a/src/Sdk/WebApi/WebApi/BrokerHttpClient.cs b/src/Sdk/WebApi/WebApi/BrokerHttpClient.cs index 8b67da2e5b9..e445b47381f 100644 --- a/src/Sdk/WebApi/WebApi/BrokerHttpClient.cs +++ b/src/Sdk/WebApi/WebApi/BrokerHttpClient.cs @@ -115,6 +115,8 @@ public async Task GetRunnerMessageAsync( { switch (brokerError.ErrorKind) { + case BrokerErrorKind.RunnerNotFound: + throw new RunnerNotFoundException(brokerError.Message); case BrokerErrorKind.RunnerVersionTooOld: throw new AccessDeniedException(brokerError.Message) { diff --git a/src/Sdk/WebApi/WebApi/Exceptions/RunnerNotFoundException.cs b/src/Sdk/WebApi/WebApi/Exceptions/RunnerNotFoundException.cs new file mode 100644 index 00000000000..957d54b89c3 --- /dev/null +++ b/src/Sdk/WebApi/WebApi/Exceptions/RunnerNotFoundException.cs @@ -0,0 +1,26 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using GitHub.Services.Common; +using GitHub.Services.WebApi; + +namespace GitHub.Services.WebApi +{ + [Serializable] + public sealed class RunnerNotFoundException : Exception + { + public RunnerNotFoundException() + : base() + { + } + + public RunnerNotFoundException(String message) + : base(message) + { + } + + public RunnerNotFoundException(String message, Exception innerException) + : base(message, innerException) + { + } + } +}