From 8352638efc2046b496282ab0ee7a5bc69f79ccef Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Tue, 11 Feb 2025 09:24:34 +0100 Subject: [PATCH] avoid `KeyError` in `handle_disconnect` (fixes #4304) --- nicegui/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nicegui/client.py b/nicegui/client.py index 6ca1119ba..c18deb942 100644 --- a/nicegui/client.py +++ b/nicegui/client.py @@ -257,6 +257,8 @@ def handle_disconnect(self, socket_id: str) -> None: In contrast to connect handlers, disconnect handlers are not called during a reconnect. This behavior should be fixed in version 3.0. """ + if socket_id not in self._socket_to_document_id: + return document_id = self._socket_to_document_id.pop(socket_id) self._cancel_delete_task(document_id) self._num_connections[document_id] -= 1