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

./contrib docs, theia: Theia proxy hangs, where Thiea on own port works correctly #332

Closed
matthew-brett opened this issue Mar 9, 2022 · 11 comments · Fixed by #458
Closed

Comments

@matthew-brett
Copy link
Contributor

Summary

I'm trying to install and run Theia via these instructions.

I have what I believe to be a minimal installation of JupyterHub / Theia working, via this Dockerfile. The image is at https://hub.docker.com/r/matthewbrett/minimal-theia-proxy.

I can get the Theia interface when running Theia from the terminal, but not when executed via jupyter_theia_proxy.

Detail

I can show that Theia is working correctly outside the JupyterHub Theia proxy by doing the following:

docker run -ti --rm -p 8888:8888 -p 3000:3000 matthewbrett/minimal-theia-proxy:82534d5

This gives the JupyterLab interface available on localhost with the link advertised in the terminal. Using the JupyterLab terminal launcher, I run the following command (see below for the theia running script):

theia start . --hostname 0.0.0.0 --port=3000

At that point, I can get a functional Theia interface at http://localhost:3000 .

However, if instead, I click on the Theia launcher, I see that the browser is trying to load http://127.0.0.1:8888/theia/ - but this hangs at what appears to be the Theia loading stage, with a dark background and spinning gray semicircle - the same thing that very briefly preceeds the successful loading of Theia above. However, in this case, the browser hangs there, and never reaches the Theia interface.

Meanwhile, in the console from which I ran the Docker run command, I get repeated messages of form:

[I 2022-03-09 17:24:11.223 ServerApp] 302 GET /socket.io/?EIO=4&transport=polling&t=NzljQir (172.17.0.1) 0.54ms
[W 2022-03-09 17:24:11.233 ServerApp] 404 GET /socket.io?EIO=4&transport=polling&t=NzljQir (172.17.0.1) 4.17ms referer=http://127.0.0.1:8888/theia/

Can you point me to where I am going wrong in using the Theia proxy here? How can I further debug?

Theia loading command

I found that the instructions at https://jupyter-server-proxy.readthedocs.io/en/latest/convenience/packages/theia.html could not work for my installation, in that the command <my-theia-build-path>/node_modules/.bin/theia will not start Theia from an arbitrary directory. I had to wrap the theia command in a shell wrapper, in order to run the command from a location where it could find the package.json file:

https://github.com/nipraxis/nipraxis-images/blob/e2dcf0ad749c7bee80a99f1fd4cbbdaf548090de/nipraxis-hub/theia-bin

Theia hostname

The command being run by jupyter_theia_proxy appears to be:

['theia', 'start', '.', '--hostname 127.0.0.1', '--port=' + str(port)]

This differs from my command run from the terminal, in that the terminal command uses --hostname 0.0.0.0.

I've tried replacing --hostname 0.0.0.0 into the jupyter_theia_proxy command, with no benefit.

@welcome
Copy link

welcome bot commented Mar 9, 2022

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@meeseeksmachine
Copy link

This issue has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/theia-on-the-littlestjupyterhub-how-to-debug/13287/9

@matthew-brett
Copy link
Contributor Author

matthew-brett commented Mar 12, 2022

Update - I had make a mistake in the Theia install - although I had installed nodejs 12 via apt in fact the build was picking up the Conda install of nodejs, version 17.

Having fixed that - the minimal Theia does start, and appears to work. It does give the following error to the terminal. I have tried installing socket.io via npm but this doesn't change the error.

[I 2022-03-12 23:07:02.183 ServerApp] Trying to establish websocket connection to ws://localhost:46655/socket.io/?EIO=4&transport=web
socket&sid=zJyZET0nG1tA3DhNAAAA                                                                                                      
[E 2022-03-12 23:07:02.189 ServerApp] Uncaught exception GET /theia/socket.io/?EIO=4&transport=websocket&sid=zJyZET0nG1tA3DhNAAAA (17
2.17.0.1)                                                                                                                            
    HTTPServerRequest(protocol='http', host='127.0.0.1:8899', method='GET', uri='/theia/socket.io/?EIO=4&transport=websocket&sid=zJyZ
ET0nG1tA3DhNAAAA', version='HTTP/1.1', remote_ip='172.17.0.1')                                                                       
    Traceback (most recent call last):                                                                                               
      File "/opt/conda/lib/python3.9/site-packages/tornado/websocket.py", line 956, in _accept_connection                            
        await open_result                                                                                                            
      File "/opt/conda/lib/python3.9/site-packages/jupyter_server_proxy/handlers.py", line 672, in open                              
        return await super().open(self.port, path)                                                                                   
      File "/opt/conda/lib/python3.9/site-packages/jupyter_server_proxy/handlers.py", line 494, in open                              
        return await self.proxy_open('localhost', port, proxied_path)                                                                
      File "/opt/conda/lib/python3.9/site-packages/jupyter_server_proxy/handlers.py", line 444, in proxy_open                        
        await start_websocket_connection()                                                                                           
      File "/opt/conda/lib/python3.9/site-packages/jupyter_server_proxy/handlers.py", line 435, in start_websocket_connection        
        self.ws = await pingable_ws_connect(request=request, 
    tornado.httpclient.HTTPClientError: HTTP 400: Bad Request
root INFO Using Git [2.25.1] from the PATH. (/usr/bin/git)
root WARN Failed to resolve module: socket.io
root WARN Failed to resolve module: ws
root WARN Failed to resolve module: filenamify
root WARN Frontend Q.configure took longer than the expected maximum 100 milliseconds: 528.0 ms [Finished 6.150 s after frontend start]
root WARN Frontend n.onStart took longer than the expected maximum 100 milliseconds: 860.0 ms [Finished 7.204 s after frontend start]
root INFO Start frontend contributions: 1685.0 ms [Finished 7.210 s after frontend start]
root INFO Changed application state from 'init' to 'started_contributions'.

https://github.com/nipraxis/nipraxis-images/blob/theia-revised/minimal-theia-proxy/Dockerfile

docker run -ti --rm -p 8888:8888 docker.io/matthewbrett/minimal-theia-proxy:b3fc530

@matthew-brett
Copy link
Contributor Author

Further - I can now get a Python version of Theia running using this package.json referring to the next package versions (latest hangs for me).

This works well via theia start . --hostname 0.0.0.0 --port 3000 or equivalent. But when used via the Theia proxy here, I get an error when the editor is opening sub-windows within in its own browser tab - for example, to give an IPython Window, or help suggestions. I get errors such as:

We can’t connect to the server at 429403e1-5f0a-4116-9f94-3c444b28b2ca.webview.127.0.0.1.

I would be very grateful for any suggestions, no matter how vague or ill-informed.

@matthew-brett
Copy link
Contributor Author

Further investigation. Adding:

ENV THEIA_WEBVIEW_EXTERNAL_ENDPOINT={{hostname}}

See: https://github.com/nipraxis/nipraxis-images/tree/cc84312 for a working Dockerfile (as long as you access via HTTPs. Image via:

docker pull matthewbrett/nibabel-theia:cc84312

resolved these errors, at the expense of a config-suppressible security warning pop-up when starting up a new Theia sub-window.

I believe there is relevant discussion there on the necessity of adapting proxies to the Webview interface.

eclipse-theia/theia#6465 (comment)

Is there any way that jupyter-server-proxy can be so adapted?

@ryanlovett
Copy link
Collaborator

Hi @matthew-brett , thanks for looking into this!

Based on my understanding of the linked webview thread, one must either host the proxied service at an https endpoint, or set an environment variable as a fallback. We currently only support contacting proxied services over http. We do support setting environment variables [1] [2]however.

@meeseeksmachine
Copy link

This issue has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/theia-on-the-littlestjupyterhub-how-to-debug/13287/12

@consideRatio
Copy link
Member

consideRatio commented Dec 29, 2022

I'm triaging issues in this repo and now look at this. I'm inclined now to dismiss it as it doesn't clearly clarify what is needed from this specific project. I have not read through everything here, but I can't sustainably triage issues if I need to dig in deep to conclude if there is an action point or bug related to this project.

@matthew-brett could you update the PR description adding a leading paragraph with how this issue relates to this specific project which is unrelated to theia with an bug / enhancement someone can work actively to resolve?

Without a clear action point tied to this project, I'd like to close it.

Update

Ah this issue is tied to theia instructions in the ./contrib folder... Hmmm, well my take is that we can't maintain them sustainably as part of this repo sadly. I'm not sure what to do with this issue since its related to the documentation in this project, but documentation I think can't be maintained as part of it.

Related

@consideRatio consideRatio changed the title Theia proxy hangs, where Thiea on own port works correctly ./contrib docs, theia: Theia proxy hangs, where Thiea on own port works correctly Dec 29, 2022
@consideRatio consideRatio changed the title ./contrib docs, theia: Theia proxy hangs, where Thiea on own port works correctly ./contrib docs, theia: Theia proxy hangs, where Thiea on own port works correctly Dec 29, 2022
@goekce
Copy link

goekce commented Oct 26, 2023

I ran into an issue where I can start theia however clicking on the files in the explorer tab does not open the files. I see the following error in my logs every time I start theia via Jupyterhub:

ServerApp Uncaught exception GET /user/test/theia/socket.io/?EIO=4&transport=websocket&sid=vaZmNWfjaVXbMVitAAAC (1.1.1.1)
HTTPServerRequest(protocol='https', host='j.server.com', method='GET', uri='/user/test/theia/socket.io/?EIO=4&transport=websocket&sid=vaZmNWfjaVXbMVitAAAC', version='HTTP/1.1', re

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/tornado/websocket.py", line 944, in _accept_connection
    await open_result
  File "/usr/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 853, in open
    return await super().open(path)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 678, in open
    return await super().open(self.port, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 557, in open
    return await self.proxy_open("localhost", port, proxied_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 505, in proxy_open
    await start_websocket_connection()
  File "/usr/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 492, in start_websocket_connection
    self.ws = await pingable_ws_connect(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
tornado.httpclient.HTTPClientError: HTTP 400: Bad Request

Using ENV THEIA_WEBVIEW_EXTERNAL_ENDPOINT='{{hostname}}' did not help. Accessing the started server using localhost:PORT works.

My logs differ a bit from #332 (comment) . Is this also related to this issue and if yes, what is the current workaround to use Theia via Jupyterhub?

@benz0li
Copy link

benz0li commented Feb 19, 2024

@goekce Try the fix proposed in #448 (comment).

@goekce
Copy link

goekce commented Feb 19, 2024

I don't have capacity to test the next time. Thanks @benz0li

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment