title: SignalR Issues with multiple requests
body: <p>In my application, I'm hosting a fairly CPU-intensive engine on a web server, which is connected to clients via SignalR. From the client, the server will be signalled to do some work (via an AJAX request), and every 200ms will send down a queue of "animation events" which describe the work being done.</p>
  
  <p>This is the code used to set up the connection on the client: </p>
  
  <pre><code>$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] })
  </code></pre>
  
  <p>And here's the related code in the backend:</p>
  
  <pre><code>    private const int PUSH_INTERVAL = 200;
      private ManualResetEvent _mrs;
  
      private void SetupTimer(bool running)
      {
          if (running)
          {
              UpdateTimer = new Timer(PushEventQueue, null, 0, PUSH_INTERVAL);
          }
          else
          {
              /* Lock here to prevent race condition where the final call to PushEventQueue()
               * could be followed by the timer calling PushEventQueue() one last time and
               * thus the End event would not be the final event to arrive clientside,
               * which causes a crash */
              _mrs = new ManualResetEvent(false);
              UpdateTimer.Dispose(_mrs);
              _mrs.WaitOne();
              Observer.End();
              PushEventQueue(null);
          }
      }
  
      private void PushEventQueue(object state)
      {
          SentMessages++;
          SignalRConnectionManager&lt;SimulationHub&gt;.PushEventQueueToClient(ConnectionId, new AnimationEventSeries { AnimationPackets = SimulationObserver.EventQueue.FlushQueue(), UpdateTime = DateTime.UtcNow });
      }
  
  
      public static void PushEventQueueToClient(string connectionId, AnimationEventSeries series)
      {
          HubContext.Clients.Client(connectionId).queue(series);
      }
  </code></pre>
  
  <p>And for completeness' sake, the related Javascript method:</p>
  
  <pre><code>self.hub.client.queue = function(data) {
      self.eventQueue.addEvents(data);
  };  
  </code></pre>
  
  <p>When testing this functionality on localhost, it works absolutely smoothly, with no delay (as you would expect), using serverSentEvents as a transport method.</p>
  
  <p>However, when used in production, this more often than not takes a very long time to complete. Using SignalR's logging and a bit of my own instrumentation, it can be seen that the first series of events reaches the client within a couple of seconds, which is totally acceptable. However, after that SignalR often gives the following error:</p>
  
  <pre><code>Keep alive has been missed, connection may be dead/slow.
  </code></pre>
  
  <p>Followed soon after by:</p>
  
  <pre><code>Keep alive timed out. Notifying transport that connection has been lost.
  </code></pre>
  
  <p>This will happen a few times, and then eventually, up to a minute later, the events will arrive, with my own instrumentation showing that they were sen from the server approximately 200ms apart, as expected. It can also be seen that in production, they were sent with the primary transport method, web sockets.</p>
  
  <p>Is anyone aware of any issues that sending multiple SignalR requests on a timer might cause? Like I say, this primarily seems to happen with web sockets. I've been told that using web sockets is best practice, so I'm keen to keep using them, but if there isn't a workaround to these kinds of issues, then I'm afraid I'll have to remove them permanently.</p>
  
  <h2>Edit</h2>
  
  <p>I've now removed the option to use web sockets on the live site, and I'm running into the same issues with server sent events - several failed attempts to reconnect after the first queue update arrives.</p>