Skip to content

Commit

Permalink
Refresh Token for BrokerServer (#3167)
Browse files Browse the repository at this point in the history
  • Loading branch information
luketomlinson authored Feb 26, 2024
1 parent d296014 commit 034c51c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Runner.Common/BrokerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface IBrokerServer : IRunnerService
Task<TaskAgentMessage> GetRunnerMessageAsync(Guid? sessionId, TaskAgentStatus status, string version, string os, string architecture, bool disableUpdate, CancellationToken token);

Task UpdateConnectionIfNeeded(Uri serverUri, VssCredentials credentials);

Task ForceRefreshConnection(VssCredentials credentials);
}

public sealed class BrokerServer : RunnerService, IBrokerServer
Expand Down Expand Up @@ -83,6 +85,11 @@ public Task UpdateConnectionIfNeeded(Uri serverUri, VssCredentials credentials)
return Task.CompletedTask;
}

public Task ForceRefreshConnection(VssCredentials credentials)
{
return ConnectAsync(_brokerUri, credentials);
}

public bool ShouldRetryException(Exception ex)
{
if (ex is AccessDeniedException ade && ade.ErrorCode == 1)
Expand Down
1 change: 1 addition & 0 deletions src/Runner.Listener/MessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ public async Task DeleteMessageAsync(TaskAgentMessage message)
public async Task RefreshListenerTokenAsync(CancellationToken cancellationToken)
{
await _runnerServer.RefreshConnectionAsync(RunnerConnectionType.MessageQueue, TimeSpan.FromSeconds(60));
await _brokerServer.ForceRefreshConnection(_creds);
}

private TaskAgentMessage DecryptMessage(TaskAgentMessage message)
Expand Down
1 change: 1 addition & 0 deletions src/Runner.Listener/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ await runServer.GetJobMessageAsync(messageRef.RunnerRequestId,
}
else if (string.Equals(message.MessageType, TaskAgentMessageTypes.ForceTokenRefresh))
{
Trace.Info("Received ForceTokenRefreshMessage");
await _listener.RefreshListenerTokenAsync(messageQueueLoopTokenSource.Token);
}
else
Expand Down

0 comments on commit 034c51c

Please sign in to comment.