Skip to content

Commit

Permalink
websockets: add configurations for ping interval and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Feb 7, 2024
1 parent 8c963a1 commit 848f77c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 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,34 @@ 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.
''',
default_value=None,
)
websocket_ping_timeout = Integer(
config=True,
help='''
Configure the websocket ping timeout in seconds.
See ``websocket_ping_interval`` for details.
''',
default_value=None,
)

config_manager_class = Type(
default_value=ConfigManager,
config=True,
Expand Down Expand Up @@ -2101,6 +2137,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

0 comments on commit 848f77c

Please sign in to comment.