-
Notifications
You must be signed in to change notification settings - Fork 95
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
keep websocket connection alive by sending pings when there is no activity #27
Conversation
…t ping message perodically when there is no activity
@@ -56,6 +63,26 @@ def initialize(self, term_manager): | |||
|
|||
self._logger = logging.getLogger(__name__) | |||
|
|||
self.keep_alive_time = 5 #send a ping if there is no activity for more than this many of seconds | |||
self.last_activity_time = keep_alive_time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assignments don't look quite right - shouldn't it be self.keep_alive_time = keep_alive_time
? And I guess last_activity_time
should be set to 0 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this.
I just made changes based on takluyver's suggestions |
|
||
def send_json_message(self, content): | ||
json_msg = json.dumps(content) | ||
self.write_message(json_msg) | ||
self.__update_last_activity_time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly for these, can they go inside an if self.keep_alive_time > 0
block?
Thanks. Just a few formatting comments now, and then it's good. |
I just updated as requested. Thanks |
Thanks! |
keep websocket connection alive by sending pings when there is no activity
I use nginx as a reverse proxy in front of terminado and jupyter. One issue I am having is that after there is no activity in the web terminal window for more than 60 seconds (default timeout in nginx), nginx will close the connection. This pull request is to add a feature to terminado to perodically send websocket "ping" frames when there is no activity. For example, if we set the keep_alive_time to 5 seconds, we will send a "ping" message when there is no activity for more than 5 seconds, No ping message will be sent when there is activity to conserve bandwidth.