Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sio.save_session() raising KeyError: 'Session not found' #1200

Closed
WebDevelopNemanja opened this issue Jun 8, 2023 · 1 comment
Closed

sio.save_session() raising KeyError: 'Session not found' #1200

WebDevelopNemanja opened this issue Jun 8, 2023 · 1 comment
Labels

Comments

@WebDevelopNemanja
Copy link

Hi,

I found that this issue #585 has been resolved but I got it on

python-socketio==5.8.0
uvicorn==0.21.1

on Python 3.11.2
Debian 11

Client latest version:
https://socket.io/docs/v4/changelog/4.6.1

Traceback (most recent call last):
File "/home/admin/sbp/lib/python3.11/site-packages/engineio/server.py", line 632, in _get_socket
s = self.sockets[sid]
~~~~~~~~~~~~^^^^^
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/admin/sbp/lib/python3.11/site-packages/socketio/asyncio_server.py", line 524, in _handle_event_internal
r = await server._trigger_event(data[0], namespace, sid, *data[1:])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/sbp/lib/python3.11/site-packages/socketio/asyncio_server.py", line 558, in _trigger_event
ret = await handler(*args)
^^^^^^^^^^^^^^^^^^^^
File "/home/admin/sbp/app/api-ws/web-socket.py", line 129, in on_authenticate
return await do_auth(sio, sid, token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/sbp/app/api-ws/web-socket.py", line 61, in do_auth
await sio.save_session(sid, user)
File "/home/admin/sbp/lib/python3.11/site-packages/socketio/asyncio_server.py", line 319, in save_session
eio_session = await self.eio.get_session(eio_sid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/sbp/lib/python3.11/site-packages/engineio/asyncio_server.py", line 109, in get_session
socket = self._get_socket(sid)
^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/sbp/lib/python3.11/site-packages/engineio/server.py", line 634, in _get_socket
raise KeyError('Session not found')
KeyError: 'Session not found'

@miguelgrinberg
Copy link
Owner

This means that the client disconnected by the time you saved the session. You can ignore the error, or catch the exception if you don't want to see it in your log. Or better yet, if at all possible, ensure that you are not saving a session after the client that owns that session left (I do understand that this may be difficult, depending on how you have your code organized).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants