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

Adds support for unix_socket #151

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
42 changes: 34 additions & 8 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 All @@ -73,17 +73,18 @@ def db_config(db_dir):
f.close()
return db_config_name

def _support_arg(arg):
def _support_args(args):
ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help'])
return ret.decode().find(arg) != -1
help_output = ret.decode()
return {arg: (help_output.find(arg) != -1) for arg in args}

def _get_www_frame_origin(default="same"):
try:
return os.getenv('JUPYTER_RSESSION_PROXY_WWW_FRAME_ORIGIN', default)
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,20 +96,42 @@ 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(),
]
# Support at least v1.2.1335 and up

if _support_arg('www-root-path'):
supported_args = _support_args([
jhgoebbert marked this conversation as resolved.
Show resolved Hide resolved
'www-root-path',
'server-data-dir',
'database-config-file',
'www-thread-pool-size',
'www-socket',
])
if supported_args['www-root-path']:
jhgoebbert marked this conversation as resolved.
Show resolved Hide resolved
cmd.append('--www-root-path={base_url}rstudio/')
if _support_arg('server-data-dir'):
if supported_args['server-data-dir']:
cmd.append(f'--server-data-dir={server_data_dir}')
if _support_arg('database-config-file'):
if supported_args['database-config-file']:
cmd.append(f'--database-config-file={database_config_file}')

if supported_args['www-thread-pool-size']:
try:
thread_pool_size = int(os.getenv('RSERVER_THREAD_POOL_SIZE', ""))
if thread_pool_size > 0:
cmd.append('--www-thread-pool-size=' + str(thread_pool_size))
except:
pass

if unix_socket != "":
if supported_args['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 +150,9 @@ def _get_timeout(default=15):
'icon_path': get_icon_path()
}
}
if os.getenv('RSERVER_USE_SOCKET', "") != "":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the above, could this please beJUPYTER_RSESSION_PROXY_USE_SOCKET instead?

Also, since you check for unix_socket != "" above, I think this can be reduced to if os.getenv("JUPYTER_RSESSION_PROXY_USE_SOCKET") ?

Copy link
Contributor Author

@jhgoebbert jhgoebbert Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that there is already RSERVER_TIMEOUT and RSESSION_TIMEOUT. So I did not want to introduce a new naming schema and named the variables also RSERVER_*.
Wouldn't it be better to change all variable names at once in a separate PR?

server_process['unix_socket'] = True

return server_process

def setup_rsession():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
keywords=['Jupyter'],
classifiers=['Framework :: Jupyter'],
install_requires=[
'jupyter-server-proxy>=3.2.3,!=4.0.0,!=4.1.0'
'jupyter-server-proxy>4.1.0'
],
entry_points={
'jupyter_serverproxy_servers': [
Expand Down