From a7db69b46483f474845333dd98687d5504260c8a Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 20:50:24 +0100 Subject: [PATCH 1/3] add unix-socket support --- jupyter_rsession_proxy/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 37f7033..107eb8a 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -51,7 +51,7 @@ def get_system_user(): return(user) def setup_rserver(): - def _get_env(port): + def _get_env(port, unix_socket): return dict(USER=get_system_user()) def db_config(db_dir): @@ -83,7 +83,7 @@ def _get_www_frame_origin(default="same"): except Exception: return default - def _get_cmd(port): + def _get_cmd(port, unix_socket): ntf = tempfile.NamedTemporaryFile() # use mkdtemp() so the directory and its contents don't vanish when @@ -95,7 +95,6 @@ def _get_cmd(port): get_rstudio_executable('rserver'), '--auth-none=1', '--www-frame-origin=' + _get_www_frame_origin(), - '--www-port=' + str(port), '--www-verify-user-agent=0', '--secure-cookie-key-file=' + ntf.name, '--server-user=' + get_system_user(), @@ -109,6 +108,14 @@ def _get_cmd(port): if _support_arg('database-config-file'): cmd.append(f'--database-config-file={database_config_file}') + if unix_socket != "": + if _support_arg('www-socket'): + cmd.append('--www-socket={unix_socket}') + else: + raise NotImplementedError(f'rstudio-server does not support requested socket connection') + else: + cmd.append('--www-port={port}') + return cmd def _get_timeout(default=15): @@ -127,6 +134,9 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } + if os.getenv('RSERVER_USE_SOCKET'): + server_process['unix_socket'] = True + return server_process def setup_rsession(): From 8745ed076c7bc51c34b60b7d415029bc4fb0a506 Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 21:04:38 +0100 Subject: [PATCH 2/3] rename var --- jupyter_rsession_proxy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 107eb8a..eaa33aa 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -134,7 +134,7 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } - if os.getenv('RSERVER_USE_SOCKET'): + if os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET'): server_process['unix_socket'] = True return server_process From 388c0e46b61911eb0b7025c0236d33468df97300 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Wed, 1 Jan 2025 13:57:49 -0800 Subject: [PATCH 3/3] Explicitly check for 'no' and 'false' in USE_SOCKET env var This allows us to default to using unix sockets by default in the future once this feature is better tested, and allow people to turn it off if needed. --- jupyter_rsession_proxy/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index eaa33aa..3b3d062 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -134,8 +134,15 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } - if os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET'): - server_process['unix_socket'] = True + + use_socket = os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET') + if use_socket is not None: + # If this env var is anything other than case insensitive 'no' or 'false', + # use unix sockets instead of tcp sockets. This allows us to default to + # using unix sockets by default in the future once this feature is better + # tested, and allow people to turn it off if needed. + if use_socket.casefold() not in ('no', 'false'): + server_process['unix_socket'] = True return server_process