| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- commit d6588c31bf0dc8e97af248a650197ba23bc097fc
- Author: Steve Sanderson <[email protected]>
- Date: Wed Jan 3 11:44:31 2018 +0000
- In Angular CLI middleware, remove additional level of timeouts since it's now covered upstream. Part of #1447
- diff --git a/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs b/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs
- index fe13b4a1c99..7f78dc96aba 100644
- --- a/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs
- +++ b/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs
- @@ -102,34 +102,25 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
- {
- // To determine when it's actually ready, try making HEAD requests to '/'. If it
- // produces any HTTP response (even if it's 404) then it's ready. If it rejects the
- - // connection then it's not ready.
- - const int MaxAttempts = 10;
- - const int SecondsBetweenAttempts = 1;
- -
- - var attemptsMade = 0;
- - var client = new HttpClient();
- -
- - while (true)
- + // connection then it's not ready. We keep trying forever because this is dev-mode
- + // only, and only a single startup attempt will be made, and there's a further level
- + // of timeouts enforced on a per-request basis.
- + using (var client = new HttpClient())
- {
- - try
- - {
- - // If we get any HTTP response, the CLI server is ready
- - await client.SendAsync(
- - new HttpRequestMessage(HttpMethod.Head, cliServerUri),
- - new CancellationTokenSource(1000).Token);
- - return;
- - }
- - catch (Exception ex)
- + while (true)
- {
- - attemptsMade++;
- - if (attemptsMade >= MaxAttempts)
- + try
- {
- - throw new InvalidOperationException(
- - "Timed out waiting for the @angular/cli server to accept HTTP requests. " +
- - "See inner exception for details.", ex);
- + // If we get any HTTP response, the CLI server is ready
- + await client.SendAsync(
- + new HttpRequestMessage(HttpMethod.Head, cliServerUri),
- + new CancellationTokenSource(1000).Token);
- + return;
- + }
- + catch (Exception)
- + {
- + await Task.Delay(1000); // 1 second
- }
- -
- - Thread.Sleep(SecondsBetweenAttempts * 1000);
- }
- }
- }
|