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

fix connection exception cause high cpu load #1484

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jupyter_server/gateway/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ 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()}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.log.warning(f"Exception connect to websocket {self.ws_future.exception()}")
self.log.warning(f"Exception connecting to websocket {self.ws_future.exception()}")

Comment on lines +149 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only log the Exception here if an exception in ws_future wouldn't already be logged, but it is. How about a simpler:

Suggested change
if self.ws_future.done() and isinstance(self.ws_future.exception(), Exception):
self.log.warning(f"Exception connect to websocket {self.ws_future.exception()}")
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)

return
loop = IOLoop.current()
loop.add_future(self.ws_future, lambda future: self.handle_incoming_message(message))
else:
Expand Down
Loading