googlecolab / jupyter_http_over_ws

Apache License 2.0
267 stars 56 forks source link

Cannot connect when port changes via proxy/ssh #23

Open blois opened 3 years ago

blois commented 3 years ago

If connecting to a local runtime via port forwarding and the port # is forwarded to a different port then the proxy will fail to connect and will generate the error:

[E 21:14:40.883 NotebookApp] Couldn't attach auth cookies
[E 21:14:59.596 NotebookApp] Uncaught error when proxying request
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/tornado/tcpclient.py", line 138, in on_connect_done
        stream = future.result()
    tornado.iostream.StreamClosedError: Stream is closed

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/jupyter_http_over_ws/handlers.py", line 179, in _attach_auth_cookies
        extra_cookies = yield _perform_request_and_extract_cookies(
      File "/opt/conda/lib/python3.8/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/conda/lib/python3.8/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/conda/lib/python3.8/site-packages/jupyter_http_over_ws/handlers.py", line 533, in _perform_request_and_extract_cookies
        response = yield http_client.fetch(proxy_request, raise_error=False)
      File "/opt/conda/lib/python3.8/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/conda/lib/python3.8/site-packages/tornado/iostream.py", line 1205, in connect
        self.socket.connect(address)
    OSError: [Errno 99] Cannot assign requested address

The connection works if I ensure that the port is not changed during the forwarding.

eszense commented 3 years ago

This is because the browser send over the auth url as is to the jupyter_http_over_ws handler, which initiate an request to this url unmodified to obtain the auth cookie. Could the handler place the server:port to the appropiate ones?