@@ -38,7 +38,8 @@ public sealed class JobServer : RunnerService, IJobServer
3838 public async Task ConnectAsync ( VssConnection jobConnection )
3939 {
4040 _connection = jobConnection ;
41- int attemptCount = 5 ;
41+ int totalAttempts = 5 ;
42+ int attemptCount = totalAttempts ;
4243 var configurationStore = HostContext . GetService < IConfigurationStore > ( ) ;
4344 var runnerSettings = configurationStore . GetSettings ( ) ;
4445
@@ -56,18 +57,21 @@ public async Task ConnectAsync(VssConnection jobConnection)
5657
5758 if ( runnerSettings . IsHostedServer )
5859 {
59- await CheckNetworkEndpointsAsync ( ) ;
60+ await CheckNetworkEndpointsAsync ( attemptCount ) ;
6061 }
6162 }
6263
63- await Task . Delay ( 100 ) ;
64+ int attempt = totalAttempts - attemptCount ;
65+ TimeSpan backoff = BackoffTimerHelper . GetExponentialBackoff ( attempt , TimeSpan . FromMilliseconds ( 100 ) , TimeSpan . FromSeconds ( 3.2 ) , TimeSpan . FromMilliseconds ( 100 ) ) ;
66+
67+ await Task . Delay ( backoff ) ;
6468 }
6569
6670 _taskClient = _connection . GetClient < TaskHttpClient > ( ) ;
6771 _hasConnection = true ;
6872 }
6973
70- private async Task CheckNetworkEndpointsAsync ( )
74+ private async Task CheckNetworkEndpointsAsync ( int attemptsLeft )
7175 {
7276 try
7377 {
@@ -79,8 +83,8 @@ private async Task CheckNetworkEndpointsAsync()
7983
8084 actionsClient . DefaultRequestHeaders . UserAgent . AddRange ( HostContext . UserAgents ) ;
8185
82- // Call the _apis/health endpoint
83- var response = await actionsClient . GetAsync ( new Uri ( baseUri , "_apis/health" ) ) ;
86+ // Call the _apis/health endpoint, and include how many attempts are left as a URL query for easy tracking
87+ var response = await actionsClient . GetAsync ( new Uri ( baseUri , $ "_apis/health?_internalRunnerAttemptsLeft= { attemptsLeft } ") ) ;
8488 Trace . Info ( $ "Actions health status code: { response . StatusCode } ") ;
8589 }
8690 }
@@ -100,8 +104,8 @@ private async Task CheckNetworkEndpointsAsync()
100104 {
101105 gitHubClient . DefaultRequestHeaders . UserAgent . AddRange ( HostContext . UserAgents ) ;
102106
103- // Call the api.github.com endpoint
104- var response = await gitHubClient . GetAsync ( "https://api.github.com" ) ;
107+ // Call the api.github.com endpoint, and include how many attempts are left as a URL query for easy tracking
108+ var response = await gitHubClient . GetAsync ( $ "https://api.github.com?_internalRunnerAttemptsLeft= { attemptsLeft } ") ;
105109 Trace . Info ( $ "api.github.com status code: { response . StatusCode } ") ;
106110 }
107111 }
0 commit comments