Skip to content

Commit a0ba8fd

Browse files
authored
Exit hosted runner cleanly during deprovisioning. (#3755)
1 parent 6b08f23 commit a0ba8fd

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

src/Runner.Common/BrokerServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Task ForceRefreshConnection(VssCredentials credentials)
9393

9494
public bool ShouldRetryException(Exception ex)
9595
{
96-
if (ex is AccessDeniedException || ex is RunnerNotFoundException)
96+
if (ex is AccessDeniedException || ex is RunnerNotFoundException || ex is HostedRunnerDeprovisionedException)
9797
{
9898
return false;
9999
}

src/Runner.Listener/BrokerMessageListener.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
249249
Trace.Info("Runner OAuth token has been revoked. Unable to pull message.");
250250
throw;
251251
}
252+
catch (HostedRunnerDeprovisionedException)
253+
{
254+
Trace.Info("Hosted runner has been deprovisioned.");
255+
throw;
256+
}
252257
catch (AccessDeniedException e) when (e.ErrorCode == 1)
253258
{
254259
throw;

src/Runner.Listener/MessageListener.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
304304
_accessTokenRevoked = true;
305305
throw;
306306
}
307+
catch (HostedRunnerDeprovisionedException)
308+
{
309+
Trace.Info("Hosted runner has been deprovisioned.");
310+
throw;
311+
}
307312
catch (AccessDeniedException e) when (e.ErrorCode == 1)
308313
{
309314
throw;

src/Runner.Listener/Runner.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ ex is TaskOrchestrationJobAlreadyAcquiredException || // HTTP status 409
697697
{
698698
Trace.Info("Runner OAuth token has been revoked. Shutting down.");
699699
}
700+
catch (HostedRunnerDeprovisionedException)
701+
{
702+
Trace.Info("Hosted runner has been deprovisioned. Shutting down.");
703+
}
700704

701705
return Constants.Runner.ReturnCode.Success;
702706
}

src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public class BrokerErrorKind
77
{
88
public const string RunnerNotFound = "RunnerNotFound";
99
public const string RunnerVersionTooOld = "RunnerVersionTooOld";
10+
public const string HostedRunnerDeprovisioned = "HostedRunnerDeprovisioned";
1011
}
1112
}

src/Sdk/WebApi/WebApi/BrokerHttpClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public async Task<TaskAgentMessage> GetRunnerMessageAsync(
122122
{
123123
ErrorCode = 1
124124
};
125+
case BrokerErrorKind.HostedRunnerDeprovisioned:
126+
throw new HostedRunnerDeprovisionedException(brokerError.Message);
125127
default:
126128
break;
127129
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace GitHub.Services.WebApi
4+
{
5+
[Serializable]
6+
public sealed class HostedRunnerDeprovisionedException : Exception
7+
{
8+
public HostedRunnerDeprovisionedException()
9+
: base()
10+
{
11+
}
12+
13+
public HostedRunnerDeprovisionedException(String message)
14+
: base(message)
15+
{
16+
}
17+
18+
public HostedRunnerDeprovisionedException(String message, Exception innerException)
19+
: base(message, innerException)
20+
{
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)