Skip to content

Commit

Permalink
Merge pull request #159 from jhgoebbert/feature/sockets-only
Browse files Browse the repository at this point in the history
Support communicating with rstudio via unix socket instead of tcp socket
  • Loading branch information
yuvipanda authored Jan 2, 2025
2 parents 35b0279 + 20f6f78 commit e31e3b1
Showing 1 changed file with 20 additions and 3 deletions.
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

0 comments on commit e31e3b1

Please sign in to comment.