Skip to content

Commit d6588c3

Browse files
In Angular CLI middleware, remove additional level of timeouts since it's now covered upstream. Part of #1447
1 parent 15d2f5a commit d6588c3

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs

+15-24
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,25 @@ private static async Task WaitForAngularCliServerToAcceptRequests(Uri cliServerU
102102
{
103103
// To determine when it's actually ready, try making HEAD requests to '/'. If it
104104
// 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())
113109
{
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)
123111
{
124-
attemptsMade++;
125-
if (attemptsMade >= MaxAttempts)
112+
try
126113
{
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
130123
}
131-
132-
Thread.Sleep(SecondsBetweenAttempts * 1000);
133124
}
134125
}
135126
}

0 commit comments

Comments
 (0)