@@ -51,7 +51,7 @@ def get_system_user():
51
51
return (user )
52
52
53
53
def setup_rserver ():
54
- def _get_env (port ):
54
+ def _get_env (port , unix_socket ):
55
55
return dict (USER = get_system_user ())
56
56
57
57
def db_config (db_dir ):
@@ -83,7 +83,7 @@ def _get_www_frame_origin(default="same"):
83
83
except Exception :
84
84
return default
85
85
86
- def _get_cmd (port ):
86
+ def _get_cmd (port , unix_socket ):
87
87
ntf = tempfile .NamedTemporaryFile ()
88
88
89
89
# use mkdtemp() so the directory and its contents don't vanish when
@@ -95,7 +95,6 @@ def _get_cmd(port):
95
95
get_rstudio_executable ('rserver' ),
96
96
'--auth-none=1' ,
97
97
'--www-frame-origin=' + _get_www_frame_origin (),
98
- '--www-port=' + str (port ),
99
98
'--www-verify-user-agent=0' ,
100
99
'--secure-cookie-key-file=' + ntf .name ,
101
100
'--server-user=' + get_system_user (),
@@ -109,6 +108,14 @@ def _get_cmd(port):
109
108
if _support_arg ('database-config-file' ):
110
109
cmd .append (f'--database-config-file={ database_config_file } ' )
111
110
111
+ if unix_socket != "" :
112
+ if _support_arg ('www-socket' ):
113
+ cmd .append ('--www-socket={unix_socket}' )
114
+ else :
115
+ raise NotImplementedError (f'rstudio-server does not support requested socket connection' )
116
+ else :
117
+ cmd .append ('--www-port={port}' )
118
+
112
119
return cmd
113
120
114
121
def _get_timeout (default = 15 ):
@@ -127,6 +134,16 @@ def _get_timeout(default=15):
127
134
'icon_path' : get_icon_path ()
128
135
}
129
136
}
137
+
138
+ use_socket = os .getenv ('JUPYTER_RSESSION_PROXY_USE_SOCKET' )
139
+ if use_socket is not None :
140
+ # If this env var is anything other than case insensitive 'no' or 'false',
141
+ # use unix sockets instead of tcp sockets. This allows us to default to
142
+ # using unix sockets by default in the future once this feature is better
143
+ # tested, and allow people to turn it off if needed.
144
+ if use_socket .casefold () not in ('no' , 'false' ):
145
+ server_process ['unix_socket' ] = True
146
+
130
147
return server_process
131
148
132
149
def setup_rsession ():
0 commit comments