From 4be5e330378c69e63d1578e246692f9cd2676ceb Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Wed, 7 Feb 2024 18:01:19 +0000 Subject: [PATCH 1/2] websockets: add configurations for ping interval and timeout --- jupyter_server/serverapp.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 9b451310ca..e4f0b4a66a 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -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: @@ -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) @@ -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( @@ -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 @@ -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, @@ -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 From b4b1b32871880301f5bb6b76a30b4f20206d8f5e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 18:10:55 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jupyter_server/serverapp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index e4f0b4a66a..5002715c90 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -1525,7 +1525,7 @@ def _default_kernel_websocket_connection_class( websocket_ping_interval = Integer( config=True, - help=''' + help=""" Configure the websocket ping interval in seconds. Websockets are long-lived connections that are used by some Jupyter @@ -1538,15 +1538,15 @@ def _default_kernel_websocket_connection_class( 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=''' + help=""" Configure the websocket ping timeout in seconds. See ``websocket_ping_interval`` for details. - ''', + """, ) config_manager_class = Type(