Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: AspNetCoreSelfHost.IsStarted set before the server actually started for real #196

Closed
davide-romanini opened this issue Sep 2, 2018 · 0 comments
Labels

Comments

@davide-romanini
Copy link
Contributor

From this code:

IsStarted = true;
#if NETSTANDARD1_3
_logger.Info("WireMock.Net server using netstandard1.3");
#elif NETSTANDARD2_0
_logger.Info("WireMock.Net server using netstandard2.0");
#elif NET46
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
#endif
#if NETSTANDARD1_3
_host.Run(_cts.Token);

is clear that IsStarted is set to true before the WebHost istance is running for real.

That causes sporadic "Connection refused" failures with code like this:

  var mockServer = FluentMockServer.Start();
  // we expect the server to be actually running and listening, but sometimes it's not still ready!
  await new HttpClient().SendAsync(new HttpRequestMessage(HttpMethod.Head, $"http:https://localhost:{mockServer.Ports[0]}"));

A better implementation could be listening for IApplicationLifetime events:

    IApplicationLifetime appLifeTime = (IApplicationLifetime)_host.Services.GetService(typeof(IApplicationLifetime));
    appLifeTime.ApplicationStarted.Register(() => {
        IsStarted = true;
    });
@StefH StefH changed the title AspNetCoreSelfHost.IsStarted setted before the server actually started for real Issue: AspNetCoreSelfHost.IsStarted set before the server actually started for real Sep 2, 2018
@StefH StefH added the bug label Sep 2, 2018
@StefH StefH closed this as completed Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants