diff --git a/socketio/asyncio_server.py b/socketio/asyncio_server.py index ae7ee874..ecdc1bf2 100644 --- a/socketio/asyncio_server.py +++ b/socketio/asyncio_server.py @@ -409,8 +409,6 @@ async def _handle_disconnect(self, sid, namespace): if namespace == '/' and self.manager.is_connected(sid, namespace): await self._trigger_event('disconnect', '/', sid) self.manager.disconnect(sid, '/') - if sid in self.environ: - del self.environ[sid] async def _handle_event(self, sid, namespace, id, data): """Handle an incoming client event.""" @@ -505,6 +503,8 @@ async def _handle_eio_message(self, sid, data): async def _handle_eio_disconnect(self, sid): """Handle Engine.IO disconnect event.""" await self._handle_disconnect(sid, '/') + if sid in self.environ: + del self.environ[sid] def _engineio_server_class(self): return engineio.AsyncServer diff --git a/socketio/server.py b/socketio/server.py index 60247ba3..68bf73c2 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -583,8 +583,6 @@ def _handle_disconnect(self, sid, namespace): if namespace == '/' and self.manager.is_connected(sid, namespace): self._trigger_event('disconnect', '/', sid) self.manager.disconnect(sid, '/') - if sid in self.environ: - del self.environ[sid] def _handle_event(self, sid, namespace, id, data): """Handle an incoming client event.""" @@ -673,6 +671,8 @@ def _handle_eio_message(self, sid, data): def _handle_eio_disconnect(self, sid): """Handle Engine.IO disconnect event.""" self._handle_disconnect(sid, '/') + if sid in self.environ: + del self.environ[sid] def _engineio_server_class(self): return engineio.Server