@@ -102,34 +102,25 @@ private static async Task WaitForAngularCliServerToAcceptRequests(Uri cliServerU
102
102
{
103
103
// To determine when it's actually ready, try making HEAD requests to '/'. If it
104
104
// produces any HTTP response (even if it's 404) then it's ready. If it rejects the
105
- // connection then it's not ready.
106
- const int MaxAttempts = 10 ;
107
- const int SecondsBetweenAttempts = 1 ;
108
-
109
- var attemptsMade = 0 ;
110
- var client = new HttpClient ( ) ;
111
-
112
- while ( true )
105
+ // connection then it's not ready. We keep trying forever because this is dev-mode
106
+ // only, and only a single startup attempt will be made, and there's a further level
107
+ // of timeouts enforced on a per-request basis.
108
+ using ( var client = new HttpClient ( ) )
113
109
{
114
- try
115
- {
116
- // If we get any HTTP response, the CLI server is ready
117
- await client . SendAsync (
118
- new HttpRequestMessage ( HttpMethod . Head , cliServerUri ) ,
119
- new CancellationTokenSource ( 1000 ) . Token ) ;
120
- return ;
121
- }
122
- catch ( Exception ex )
110
+ while ( true )
123
111
{
124
- attemptsMade ++ ;
125
- if ( attemptsMade >= MaxAttempts )
112
+ try
126
113
{
127
- throw new InvalidOperationException (
128
- "Timed out waiting for the @angular/cli server to accept HTTP requests. " +
129
- "See inner exception for details." , ex ) ;
114
+ // If we get any HTTP response, the CLI server is ready
115
+ await client . SendAsync (
116
+ new HttpRequestMessage ( HttpMethod . Head , cliServerUri ) ,
117
+ new CancellationTokenSource ( 1000 ) . Token ) ;
118
+ return ;
119
+ }
120
+ catch ( Exception )
121
+ {
122
+ await Task . Delay ( 1000 ) ; // 1 second
130
123
}
131
-
132
- Thread . Sleep ( SecondsBetweenAttempts * 1000 ) ;
133
124
}
134
125
}
135
126
}
0 commit comments