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 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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 @@ -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()}")
Copy link
Contributor

@minrk minrk Dec 19, 2024

Choose a reason for hiding this comment

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

future.done() does not imply that it failed, whereas log message assumes it has.

Maybe the fix here is to add and not self.ws_future.done() to the condition on line 148? Or more lkely, the ws future error was already logged, and the right thing to do here is a debug (or warning, I'm not sure)-log for "message on closed websocket"?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah,you are right,I adjust it

Copy link
Author

Choose a reason for hiding this comment

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

maybe like this

            if self.ws_future.done() and isinstance(self.ws_future.exception(), Exception):
                self.log.error(f"Exception connect to server {self.ws_future.exception()}")
                return

if use if self.ws is None and not self.ws_future.done() when raise connection err,code will execute else logic self._write_message(message)

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