From 0a35f5d88b81649465b33248d4e393de45ff9de9 Mon Sep 17 00:00:00 2001 From: chengcong Date: Wed, 18 Dec 2024 23:20:18 +0800 Subject: [PATCH 1/4] fix connection exception cause high cpu load adjust err log --- jupyter_server/gateway/connections.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jupyter_server/gateway/connections.py b/jupyter_server/gateway/connections.py index d4dde730fa..c58318e70b 100644 --- a/jupyter_server/gateway/connections.py +++ b/jupyter_server/gateway/connections.py @@ -147,6 +147,9 @@ def handle_incoming_message(self, message: str) -> None: """Send message to gateway server.""" if self.ws is None and self.ws_future is not None: loop = IOLoop.current() + if self.ws_future.done(): + self.log.error(f"Exception connect to gateway server {self.ws_future.exception()}") + return loop.add_future(self.ws_future, lambda future: self.handle_incoming_message(message)) else: self._write_message(message) From 0839c93424e9ef5cafc378d8829fee87faf29d00 Mon Sep 17 00:00:00 2001 From: chengcong Date: Fri, 20 Dec 2024 11:52:41 +0800 Subject: [PATCH 2/4] adjust code --- jupyter_server/gateway/connections.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyter_server/gateway/connections.py b/jupyter_server/gateway/connections.py index c58318e70b..89504d8fd8 100644 --- a/jupyter_server/gateway/connections.py +++ b/jupyter_server/gateway/connections.py @@ -146,10 +146,10 @@ def handle_outgoing_message(self, incoming_msg: str, *args: Any) -> None: def handle_incoming_message(self, message: str) -> None: """Send message to gateway server.""" if self.ws is None and self.ws_future is not None: - loop = IOLoop.current() - if self.ws_future.done(): - self.log.error(f"Exception connect to gateway server {self.ws_future.exception()}") + if self.ws_future.done() and isinstance(self.ws_future.exception, Exception): + self.log.warning(f"Exception connect to websocket {self.ws_future.exception()}") return + loop = IOLoop.current() loop.add_future(self.ws_future, lambda future: self.handle_incoming_message(message)) else: self._write_message(message) From 103a57a8cf93b5625411648aa17370decfbaa30f Mon Sep 17 00:00:00 2001 From: chengcong1 Date: Fri, 20 Dec 2024 13:05:35 +0800 Subject: [PATCH 3/4] upate code --- jupyter_server/gateway/connections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_server/gateway/connections.py b/jupyter_server/gateway/connections.py index 89504d8fd8..37d62d2f7e 100644 --- a/jupyter_server/gateway/connections.py +++ b/jupyter_server/gateway/connections.py @@ -146,7 +146,7 @@ def handle_outgoing_message(self, incoming_msg: str, *args: Any) -> None: def handle_incoming_message(self, message: str) -> None: """Send message to gateway server.""" if self.ws is None and self.ws_future is not None: - if self.ws_future.done() and isinstance(self.ws_future.exception, Exception): + if self.ws_future.done() and isinstance(self.ws_future.exception(), Exception): self.log.warning(f"Exception connect to websocket {self.ws_future.exception()}") return loop = IOLoop.current() From 03d023d6fcc9d77de0373097aa8a25825be6e0dd Mon Sep 17 00:00:00 2001 From: chengcong1 Date: Mon, 23 Dec 2024 09:15:28 +0800 Subject: [PATCH 4/4] adjust code --- jupyter_server/gateway/connections.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jupyter_server/gateway/connections.py b/jupyter_server/gateway/connections.py index 37d62d2f7e..2bce86be81 100644 --- a/jupyter_server/gateway/connections.py +++ b/jupyter_server/gateway/connections.py @@ -146,9 +146,10 @@ def handle_outgoing_message(self, incoming_msg: str, *args: Any) -> None: def handle_incoming_message(self, message: str) -> None: """Send message to gateway server.""" if self.ws is None and self.ws_future is not None: - if self.ws_future.done() and isinstance(self.ws_future.exception(), Exception): - self.log.warning(f"Exception connect to websocket {self.ws_future.exception()}") - return + if self.ws_future.done() and self.ws_future.exception() is not None: + self.log.warning( + "Ignoring message on failed connection to kernel %s", self.kernel_id + ) loop = IOLoop.current() loop.add_future(self.ws_future, lambda future: self.handle_incoming_message(message)) else: