Note that there are some explanatory texts on larger screens.

plurals
  1. PODisconnect not firing sometimes in signalR
    text
    copied!<p>I currently keep my users in a table called OnlineUsers. When a person connects or disconnects it adds the userid and his connectionid to the table, but for some reason (i believe when multiple browser windows are open) the Disconnect function does not fire sometimes, leaving users in the table and making them appear "online" when they really aren't. Has anyone ran into this problem before and what would be a good way to fix this issue?</p> <p>UPDATE** (sorry about not putting code, I should have done it in the first place)</p> <p>Here are my db functions to add and remove from the table:</p> <pre><code> public bool ConnectUser(Guid UserId, String ConnectionId) { if (!Ent.OnlineUsers.Any(x =&gt; x.UserId == UserId &amp;&amp; x.ConnectionId == ConnectionId)) { Ent.OnlineUsers.AddObject(new OnlineUser { UserId = UserId, ConnectionId = ConnectionId }); Ent.SaveChanges(); return true; } else return false; } public void DisconnectUser(Guid UserId, String ConnectionId) { if (Ent.OnlineUsers.Any(x =&gt; x.UserId == UserId &amp;&amp; x.ConnectionId == ConnectionId)) { Ent.OnlineUsers.DeleteObject(Ent.OnlineUsers.First(x =&gt; x.UserId == UserId &amp;&amp; x.ConnectionId == ConnectionId)); Ent.SaveChanges(); } } </code></pre> <p>Here is my hub class connect and disconnect task:</p> <pre><code> public Task Disconnect() { disconnectUser(); return null; } public Task Reconnect(IEnumerable&lt;string&gt; connections) { connectUser(); return null; } public Task Connect() { connectUser(); return null; } private void connectUser() { if (onlineUserRepository.ConnectUser(MainProfile.UserId, Context.ConnectionId)) { Groups.Add(Context.ConnectionId, Convert.ToString(MainProfile.ChatId)); } } private void disconnectUser() { onlineUserRepository.DisconnectUser(MainProfile.UserId, Context.ConnectionId); Groups.Remove(Context.ConnectionId, Convert.ToString(MainProfile.ChatId)); } </code></pre> <p>I have checked that I am on the latest version of signalR (0.5.3) and this seems to happen when I have multiple browser windows open and I close them all at once, the users will get stuck in the database.</p> <p>In case this is needed, this is my Connection Id Generator class:</p> <pre><code>public class MyConnectionFactory : IConnectionIdGenerator { public string GenerateConnectionId(IRequest request) { if (request.Cookies["srconnectionid"] != null) { return request.Cookies["srconnectionid"].ToString(); } return Guid.NewGuid().ToString(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload