OnDisconnect and Logged on Users after recycle?

廉价感情. 提交于 2020-01-05 05:49:07

问题


I've read that OnDisconnect ( server side) sometimes , can be bypassed ( application recycle etc).

The OnDisconnected method doesn't get called in some scenarios, such as when a server goes down or the App Domain gets recycled.

And so I ask :

When a user connects , I generate him a token , keep it in the user cookie , and when OnConnect is called , I attach a connectionId with that token.

(the same way where onDiconnect is called , I set a value in the dateDisconnected)

This will also supports 2 connected users ( same browser)

example :

example :

id         tokenId              ConnectionID         DateCreated            dateDisconnected
----------------------------------------------------------------------------------------------
1          500                    {1234-1234}          06-07-2013               null             
2          500                    {5432-5432}          06-07-2013               null             

And here is the problem :

What will happen if a user has logged in (So I write this user in my DB as logged in) , do some chat , and then the server restarted ?

The client will try to reconnect and after 30 seconds it will stop.

But then , when the server is UP (after an hour ) - I STILL HAVE A LOGGED ON USER IN MY DB. and he is NOT. ( well , not with that connection ID anyway...)

How can I solve this kind of problem ?


回答1:


The best way to solve this problem is to log everyone out on application start, aka in your case invalidate/delete all logged in token rows. Therefore whenever the server comes up the application is in a fresh state with no one logged in.



来源:https://stackoverflow.com/questions/17510163/ondisconnect-and-logged-on-users-after-recycle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!