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

Support communicating with rstudio via unix socket instead of tcp socket #159

Merged
merged 4 commits into from
Jan 2, 2025
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
23 changes: 20 additions & 3 deletions jupyter_rsession_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand All @@ -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):
Expand All @@ -127,6 +134,16 @@ def _get_timeout(default=15):
'icon_path': get_icon_path()
}
}

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

def setup_rsession():
Expand Down