SignalR/SignalR — Issue #169: Connections may not be getting cleaned up correctly
Author: abillingsley
Created: 2012-02-01 14:48:57+00:00
State: open

I need to preface this bug by saying I am not sure if this bug is really an issue with the server or the client. Issue [44](https://github.com/DyKnow/SignalR-ObjC/issues/44) in the Objective C repo goes into more details

### What I am looking for
- you guys know the server code better than me if something comes to mind and you can point me in a direction that would be help enough (i hope)
- I do not expect you to debug the objective c client for me, although if you looked at the code it would seem very familiar since it is basically a c# clone.

### Observations while debugging
- When setting a breakpoint at the for loop the `_connection.count()` seems to always be what signalr expects number of connections to be this normally maps to what iis sees as the number of Executing requests. `_connections.count()` will stay at the expected number of connections after the objective c client running server sent events times out but IIS will increment the number of connections, this disconnect will continue until new data is received on the connection. If the connection remains idle long enough IIS Express will max out its connections and prevent any new connections from being created.

```c#
private void Beat(object state)
{
if (Interlocked.Exchange(ref _running, 1) == 0)
{
Trace.TraceInformation("SIGNALR: TransportHeatBeat timer handler took longer than current interval");
return;
}

try
{
foreach (var connection in _connections.GetSnapshot())
{
....
}
}
}
```

- to test I enhanced the SignalR.Client.Samples to support a mouse tracking sample. The c# client clearly decrements the iis requests executing counter before the new connection is established. this does not happen on objective c
- I have only been able to replicate this with the objective c client using server sent events (which implies a client problem)