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

keep websocket connection alive by sending pings when there is no activity #27

Merged
merged 3 commits into from
Feb 6, 2016

Conversation

zyzhu2000
Copy link

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.

…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
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for catching this.

@zyzhu2000
Copy link
Author

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()
Copy link
Member

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?

@takluyver
Copy link
Member

Thanks. Just a few formatting comments now, and then it's good.

@zyzhu2000
Copy link
Author

I just updated as requested. Thanks

@takluyver
Copy link
Member

Thanks!

takluyver added a commit that referenced this pull request Feb 6, 2016
 keep websocket connection alive by sending pings when there is no activity
@takluyver takluyver merged commit 1c591fa into jupyter:master Feb 6, 2016
takluyver added a commit that referenced this pull request Feb 10, 2016
This reverts commit 1c591fa, reversing
changes made to fcd5f74.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants