Skip to content

Commit

Permalink
Handle runner not found (#3536)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple authored Nov 5, 2024
1 parent 3d34a3c commit 2c03d74
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Runner.Common/BrokerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Runner.Listener/BrokerMessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -241,6 +242,10 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
{
throw;
}
catch (RunnerNotFoundException)
{
throw;
}
catch (Exception ex)
{
Trace.Error("Catch exception during get next message.");
Expand Down Expand Up @@ -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}");
Expand Down
5 changes: 5 additions & 0 deletions src/Runner.Listener/MessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
{
throw;
}
catch (RunnerNotFoundException)
{
throw;
}
catch (Exception ex)
{
Trace.Error("Catch exception during get next message.");
Expand Down Expand Up @@ -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}");
Expand Down
7 changes: 7 additions & 0 deletions src/Runner.Listener/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using GitHub.DistributedTask.WebApi;
using GitHub.Services.WebApi;

namespace GitHub.Runner.Listener
{
Expand Down Expand Up @@ -144,6 +145,12 @@ private async static Task<int> 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}");
Expand Down
1 change: 1 addition & 0 deletions src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace GitHub.Actions.RunService.WebApi
[DataContract]
public class BrokerErrorKind
{
public const string RunnerNotFound = "RunnerNotFound";
public const string RunnerVersionTooOld = "RunnerVersionTooOld";
}
}
2 changes: 2 additions & 0 deletions src/Sdk/WebApi/WebApi/BrokerHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public async Task<TaskAgentMessage> GetRunnerMessageAsync(
{
switch (brokerError.ErrorKind)
{
case BrokerErrorKind.RunnerNotFound:
throw new RunnerNotFoundException(brokerError.Message);
case BrokerErrorKind.RunnerVersionTooOld:
throw new AccessDeniedException(brokerError.Message)
{
Expand Down
26 changes: 26 additions & 0 deletions src/Sdk/WebApi/WebApi/Exceptions/RunnerNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}

0 comments on commit 2c03d74

Please sign in to comment.