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

websockets: add configurations for ping interval and timeout #1391

Merged
merged 2 commits into from
Feb 15, 2024
Merged
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
36 changes: 36 additions & 0 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ def __init__(
authorizer=None,
identity_provider=None,
kernel_websocket_connection_class=None,
websocket_ping_interval=None,
websocket_ping_timeout=None,
):
"""Initialize a server web application."""
if identity_provider is None:
Expand Down Expand Up @@ -277,6 +279,8 @@ def __init__(
authorizer=authorizer,
identity_provider=identity_provider,
kernel_websocket_connection_class=kernel_websocket_connection_class,
websocket_ping_interval=websocket_ping_interval,
websocket_ping_timeout=websocket_ping_timeout,
)
handlers = self.init_handlers(default_services, settings)

Expand All @@ -301,6 +305,8 @@ def init_settings(
authorizer=None,
identity_provider=None,
kernel_websocket_connection_class=None,
websocket_ping_interval=None,
websocket_ping_timeout=None,
):
"""Initialize settings for the web application."""
_template_path = settings_overrides.get(
Expand Down Expand Up @@ -383,6 +389,8 @@ def init_settings(
"identity_provider": identity_provider,
"event_logger": event_logger,
"kernel_websocket_connection_class": kernel_websocket_connection_class,
"websocket_ping_interval": websocket_ping_interval,
"websocket_ping_timeout": websocket_ping_timeout,
# handlers
"extra_services": extra_services,
# Jupyter stuff
Expand Down Expand Up @@ -1515,6 +1523,32 @@ def _default_kernel_websocket_connection_class(
return "jupyter_server.gateway.connections.GatewayWebSocketConnection"
return ZMQChannelsWebsocketConnection

websocket_ping_interval = Integer(
config=True,
help="""
Configure the websocket ping interval in seconds.

Websockets are long-lived connections that are used by some Jupyter
Server extensions.

Periodic pings help to detect disconnected clients and keep the
connection active. If this is set to None, then no pings will be
performed.

When a ping is sent, the client has ``websocket_ping_timeout``
seconds to respond. If no response is received within this period,
the connection will be closed from the server side.
""",
)
websocket_ping_timeout = Integer(
config=True,
help="""
Configure the websocket ping timeout in seconds.

See ``websocket_ping_interval`` for details.
""",
)

config_manager_class = Type(
default_value=ConfigManager,
config=True,
Expand Down Expand Up @@ -2101,6 +2135,8 @@ def init_webapp(self) -> None:
authorizer=self.authorizer,
identity_provider=self.identity_provider,
kernel_websocket_connection_class=self.kernel_websocket_connection_class,
websocket_ping_interval=self.websocket_ping_interval,
websocket_ping_timeout=self.websocket_ping_timeout,
)
if self.certfile:
self.ssl_options["certfile"] = self.certfile
Expand Down
Loading