-
Notifications
You must be signed in to change notification settings - Fork 151
Proxying Xpra is not working #35
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
Comments
Looks like it is Xpra issue, it doesn't handle websocket paths. Close for now. |
I've updated Xpra and now it recognizes that it runs with some path in URL. Still it has problems with websockets. FROM centos:7
RUN \
yum -y install \
epel-release \
https://centos7.iuscommunity.org/ius-release.rpm \
&& rm -rf /var/cache/yum/
ADD https://xpra.org/repos/CentOS/xpra.repo /etc/yum.repos.d/
RUN \
yum install -y \
python36u python36u-libs python36u-devel python36u-pip \
xpra python-websockify xterm \
&& rm -rf /var/cache/yum/
RUN pip3.6 --no-cache-dir install \
'notebook==5.5.0' \
'nbserverproxy'
RUN jupyter serverextension enable --py nbserverproxy
RUN dbus-uuidgen > /etc/machine-id
CMD ["jupyter", "notebook"]
Then run it with
and wait until it writes Go to http://localhost:14500/ and see xterm in your browser. Go to http://localhost:8888/proxy/14500/ and see Xpra HTML5 client trying to connect to websocket with no luck When I connect to http://localhost:14500/, the response to websocket Upgrade request is
But behind nbserverproxy the response is
|
Hey @BerserkerTroll, thanks for reporting this issue. I think supporting Xpra would be cool, but I may not get to look at this for a few weeks. At first glance, /proxy/14500/ != //proxy/14500, so something may be amiss with slash parsing or requesting. |
I think now it is not about supporting Xpra, it feels like a general WebSocket proxying issue.
Indeed, it helped. A bit. Now it is able to connect to WebSocket (The message "Opening WebSocket connection" changed to "WebSocket connection established"), but it never shows xterm and after 10-15 seconds throws me to
Errors from Xpra (just in case):
Ofc, I do not see these errors when I connect directly to localhost:14500. Looks like the websocket data is corrupted somehow on the way from the Xpra client to the Xpra server. |
I've debugged it in Wireshark a bit. I've spotted very strange things. The proxy answers to Upgrade request immediately with HTTP 101 "Switching protocol", before it even sends the request to the backend! Probably I'm bad at asynchronous programming, but this looks too asynchronous for me. In details, when I connect directly, HTML5 client switches protocol to websocket and sends "hello" packet to the Xpra server:
Behind the proxy, the "hello" message never gets to the backend:
|
Well, I've added 1 second delay before "hello" message is sent and now the HTML5 client is able to connect and show me the xterm window. But not everything working as expected. Without a window manager running, the HTML5 client draws window frames itself and loads png-images of close and minimize buttons from the server. However, these images can't be loaded through the proxy. It looks that the WebSocket proxying logics is flawed: the https://stackoverflow.com/questions/38663666/how-can-i-serve-a-http-page-and-a-websocket-on-the-same-url-in-tornado method is not intended for proxies. The proxy is answering immediately to the Upgrade request whilst it shall respond with the backend response. |
I don't know how stupid is this asyncprogrammingwise, because I don't know much about Python and Tornado. --- a/nbserverproxy/handlers.py
+++ b/nbserverproxy/handlers.py
@@ -93,12 +93,11 @@ class WebSocketHandlerMixin(websocket.WebSocketHandler):
async def get(self, *args, **kwargs):
if self.request.headers.get("Upgrade", "").lower() != 'websocket':
return await self.http_get(*args, **kwargs)
- # super get is not async
- super().get(*args, **kwargs)
+ return await self.ws_get(*args, **kwargs)
class LocalProxyHandler(WebSocketHandlerMixin, IPythonHandler):
- async def open(self, port, proxied_path=''):
+ async def ws_get(self, port, proxied_path=''):
"""
Called when a client opens a websocket connection.
@@ -144,12 +143,18 @@ class LocalProxyHandler(WebSocketHandlerMixin, IPythonHandler):
self.log.info('Trying to establish websocket connection to {}'.format(client_uri))
self._record_activity()
request = httpclient.HTTPRequest(url=client_uri, headers=headers)
- self.ws = await pingable_ws_connect(request=request,
- on_message_callback=message_cb, on_ping_callback=ping_cb)
- self._record_activity()
- self.log.info('Websocket connection established to {}'.format(client_uri))
+ try:
+ self.ws = await pingable_ws_connect(request=request,
+ on_message_callback=message_cb, on_ping_callback=ping_cb)
+ except Exception:
+ self.set_status(400)
+ else:
+ self._record_activity()
+ self.log.info('Websocket connection established to {}'.format(client_uri))
+ # super get is not async
+ super(WebSocketHandlerMixin, self).get(port, proxied_path)
- ioloop.IOLoop.current().add_callback(start_websocket_connection)
+ return await start_websocket_connection()
def on_message(self, message):
""" |
Just wanted to say thanks for your patience @BerserkerTroll! I'll be able to look at this and your PR soon. |
Uh oh!
There was an error while loading. Please reload this page.
UDP: a way to reproduce: #35 (comment)
UPD: proposed fix: #35 (comment)
I've tried to proxy Xpra html5 client with
nbserverproxy
(version 0.8.3), but it doesn't seem to work.When I start Xpra on a local machine with the
command and open
localhost:14500
, I seexterm
in my browser.I've tried to run this command from the
jupyter
terminal and then access.../proxy/14500
.It struggles to Update connection to WebSocket.
When I connect directly, the response to Upgrade request is
But behind nbserverproxy the response is
There is Wiki page about proxying Xpra with Nginx: https://www.xpra.org/trac/wiki/Nginx
AFAIU it makes Nginx to do something to HTTP headers so that websockets work behind a proxy.
I know about https://github.com/ryanlovett/nbnovnc/, but I would like to see Xpra working.
The text was updated successfully, but these errors were encountered: