unclose session after disconnect
See original GitHub issueserver.py
sio = socketio.AsyncServer(
async_mode='asgi', client_manager=mgr, cors_allowed_origins="*")
@sio.event
async def connect(sid, environ):
claims = get_jwt_claims_from_environ(environ)
ga = get_ga_from_environ(environ)
async with sio.session(sid) as session:
await Lock().wait()
if claims:
user_ID = claims.get('user_ID')
session['user_ID'] = user_ID
ret = await RedisClient.add_to_set(user_ID)
if not ret:
raise ConnectionRefusedError('Duplicate connect')
@sio.event
async def disconnect(sid):
async with sio.session(sid) as session:
user_ID = session.get('user_ID')
if user_ID is not None:
await RedisClient.remove_from_set(session.get('user_ID', ''))
version:
# python 3.6.9
aioredis 1.3.1
async-timeout 3.0.1
click 7.1.1
h11 0.9.0
hiredis 1.0.1
httptools 0.1.1
pip 19.3.1
python-engineio 3.12.1
python-socketio 4.5.0
setuptools 41.6.0
six 1.14.0
uvicorn 0.11.3
uvloop 0.14.0
websockets 8.1
wheel 0.33.6
start:
uvicorn server:app --host 0.0.0.0 --workers 1 --log-level error --use-colors
nginx conf:
location /socketio/ {
proxy_pass http://localhost:8888/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
When connect, I store user_ID
in session and redis sets. If user_ID
exists in redis sets, i will refuse connect.
When disconnect, remove user_ID from redis sets.
I find some user_ID not exists in redis sets but in session, I get session use follow code:
def get_online_user(sio):
for s in sio.eio.sockets.values():
session = s.session.get('/', {})
if session.get('user_ID') is not None:
online_user.append(session['user_ID'])
return online_user
Sometimes, it has duplicate user_ID in session.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Windows 10 RDP session closes after disconnecting. - TechNet
Now if I close the session, the user log off and stop what was doing, so I have to maintain RDP connection open...
Read more >Session logged out after disconnection of remote connection
On the Windows 7 server, start gpedit.msc , browse to Computer Configuration --> Administrative Templates --> Windows Components --> Remote ...
Read more >How to set time limit for disconnected sessions Windows ...
You can limit the amount of time that active, disconnected, and idle sessions remain on the server. Two methods are described below:
Read more >Exiting RemoteApp session leaves disconnected RDP session
The problem is that when the users exit the RemoteApp, their session is showing on the server as 'disconnected'. Is there any way...
Read more >Reconnecting to an existing session - http:\\hazards.fema.gov
The session begins when the user logs into the server (step 3) and ends when the ... Disconnected Session: the time period during...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello! I’ve noticed the same issue (I guess) with using SocketIO as a server to run. For some reason, the closed sockets are not being deleted from within the EngineIO, and they remain in memory, despite the fact that they are closed. I’ve been tracking the memory usage of my app, and it appears to be that when I refresh the browser page, I’m getting some memory leaks. I’ve logged out the sockets via simple script:
And the result looked quite sad, like so (don’t mind the queue size, I’m broadcasting quite a lot of data, so no surprises here):
The worst part is that even when the selenium script is stopped and all the browsers closed, those sockets are not going anywhere.
I can, of course, clean them up manually via this code:
But this just don’t seem to be right thing to do.
My setup is straight forward
SocketIO(http_compression=True).run()
with no Gunicorn neither Nginx to mess up with.I’ve been looking into why my application code doesn’t close old connections. It seems this is the very same issue I’m facing. Any update on this?