title: Cannot shut down and start new SignalR using OWIN Self Host
body: <p>This is a heck of a wall to hit at the end of a 1.5 week refactoring.</p>
  
  <p>I've gotten it down to the bear minimum and I'm at an absolute loss</p>
  
  <p>I start a SignalR webserver using owin selfhost (katana), connect to it. I shut it down, and then I start it and try to connect to it again. </p>
  
  <p>On the <strong>second</strong> time through (it works just fine the first time) I get an error while trying to initiate a connection:</p>
  
  <pre><code>public partial class App : Application
  {
  
      void App_Startup(object sender, StartupEventArgs e)
      {
          using (var server = new TestWebServer()) {
              server.Start();
              using (var hubConnection = new HubConnection(TestWebServer.Host)) {
                  var proxy = hubConnection.CreateHubProxy("testHub");
                  hubConnection.Start().Wait();
                  Debug.Assert(hubConnection.State == ConnectionState.Connected);
              }
          }
  
          // Makes it here fine
  
          using (var server = new TestWebServer()) {
              server.Start();
              using (var hubConnection = new HubConnection(TestWebServer.Host)) {
                  var proxy = hubConnection.CreateHubProxy("testHub");
                  hubConnection.Start().Wait(); //&lt;-throws "Transport timed out trying to connect"
                  Debug.Assert(hubConnection.State == ConnectionState.Connected);
              }
          }
      }
  }
  </code></pre>
  
  <p>With <code>TestWebServer</code>:</p>
  
  <pre><code>public class TestWebServer : IDisposable {
      public const string Host = "http://localhost:8081/";
      public void Start() {
          if (null != server) return;
          this.server = WebApp.Start(Host, app =&gt; {
              var cfg = new HubConfiguration { };
              app.MapSignalR(cfg);
          });
      }
      IDisposable server;
  
      //Super-duper-for-real disposable https://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/
      bool _disposed;
      public void Dispose() {
          Dispose(true);
          GC.SuppressFinalize(this);
      }
      ~TestWebServer() {
          Dispose(false);
      }
      protected virtual void Dispose(bool disposing) {
          if (_disposed)
              return;
          if (disposing) {
              if (null == server) return;
              server.Dispose();
              server = null;
          }
          _disposed = true;
      }
  
  }
  </code></pre>
  
  <p>And <code>TestHub</code></p>
  
  <pre><code>[HubName("testHub")]
  public class TestHub : Hub {
      public void Ping() =&gt; Clients.All.pong();
  }
  </code></pre>
  
  <p>This is using SignalR 2.2.0 and I've tried both on .Net 4.5 and 4.6.1</p>
  
  <p>This is as simple a SignalR application as I possibly know how to make it and you notice it works! Once. Then it fails when I dispose and try the exact same code again.</p>
  
  <p>What is going on? Is there something else that I need to do to dispose of things?</p>
  
  <p>Yes, I've tried to <code>Thread.Sleep</code> between the two.</p>
  
  <p><a href="https://github.com/togakangaroo/SignalRHasIssues" rel="noreferrer">Here is a tester project demonstrating the issue</a></p>