2
0

JavaScriptServices 376 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. commit d6588c31bf0dc8e97af248a650197ba23bc097fc
  2. Author: Steve Sanderson <[email protected]>
  3. Date: Wed Jan 3 11:44:31 2018 +0000
  4. In Angular CLI middleware, remove additional level of timeouts since it's now covered upstream. Part of #1447
  5. diff --git a/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs b/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs
  6. index fe13b4a1c99..7f78dc96aba 100644
  7. --- a/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs
  8. +++ b/src/Microsoft.AspNetCore.SpaServices.Extensions/AngularCli/AngularCliMiddleware.cs
  9. @@ -102,34 +102,25 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
  10. {
  11. // To determine when it's actually ready, try making HEAD requests to '/'. If it
  12. // produces any HTTP response (even if it's 404) then it's ready. If it rejects the
  13. - // connection then it's not ready.
  14. - const int MaxAttempts = 10;
  15. - const int SecondsBetweenAttempts = 1;
  16. -
  17. - var attemptsMade = 0;
  18. - var client = new HttpClient();
  19. -
  20. - while (true)
  21. + // connection then it's not ready. We keep trying forever because this is dev-mode
  22. + // only, and only a single startup attempt will be made, and there's a further level
  23. + // of timeouts enforced on a per-request basis.
  24. + using (var client = new HttpClient())
  25. {
  26. - try
  27. - {
  28. - // If we get any HTTP response, the CLI server is ready
  29. - await client.SendAsync(
  30. - new HttpRequestMessage(HttpMethod.Head, cliServerUri),
  31. - new CancellationTokenSource(1000).Token);
  32. - return;
  33. - }
  34. - catch (Exception ex)
  35. + while (true)
  36. {
  37. - attemptsMade++;
  38. - if (attemptsMade >= MaxAttempts)
  39. + try
  40. {
  41. - throw new InvalidOperationException(
  42. - "Timed out waiting for the @angular/cli server to accept HTTP requests. " +
  43. - "See inner exception for details.", ex);
  44. + // If we get any HTTP response, the CLI server is ready
  45. + await client.SendAsync(
  46. + new HttpRequestMessage(HttpMethod.Head, cliServerUri),
  47. + new CancellationTokenSource(1000).Token);
  48. + return;
  49. + }
  50. + catch (Exception)
  51. + {
  52. + await Task.Delay(1000); // 1 second
  53. }
  54. -
  55. - Thread.Sleep(SecondsBetweenAttempts * 1000);
  56. }
  57. }
  58. }