jupyter-collaboration icon indicating copy to clipboard operation
jupyter-collaboration copied to clipboard

'YDocWebSocketHandler' object has no attribute 'room'

Open martinRenou opened this issue 1 year ago • 18 comments

I'm getting the following error with jupyter-collaboration 2.1.1:

    Traceback (most recent call last):
      File "/home/martin/micromamba/envs/jupytercad/lib/python3.12/site-packages/tornado/ioloop.py", line 750, in _run_callback
        ret = callback()
              ^^^^^^^^^^
      File "/home/martin/micromamba/envs/jupytercad/lib/python3.12/site-packages/tornado/websocket.py", line 640, in <lambda>
        self.stream.io_loop.add_future(result, lambda f: f.result())
                                                         ^^^^^^^^^^
      File "/home/martin/micromamba/envs/jupytercad/lib/python3.12/site-packages/jupyter_collaboration/handlers.py", line 286, in on_message
        changes = self.room.awareness.get_changes(message[1:])
                  ^^^^^^^^^
    AttributeError: 'YDocWebSocketHandler' object has no attribute 'room'

martinRenou avatar Jul 02 '24 09:07 martinRenou

Could you try updating to jupyter-collaboration v3.0.0.a2?

davidbrochart avatar Jul 02 '24 09:07 davidbrochart

When using jupyter-collaboration 3.0.0a2 I'm getting a front-end error when trying to open a file

Screenshot from 2024-07-02 11-37-29

martinRenou avatar Jul 02 '24 09:07 martinRenou

Is this (the v3.0a2 issue) when opening a plain text file or when opening the CAD file?

krassowski avatar Jul 16 '24 16:07 krassowski

It was when opening a CAD file. We should try to upgrade jupyter collaboration there with the recent beta.

martinRenou avatar Jul 17 '24 11:07 martinRenou

I can reproduce this exception when attempting to create a test notebook on main:


HTTPServerRequest(protocol='http', host='127.0.0.1:35807', method='GET', uri='/a%40b/api/collaboration/room/json:notebook:649151c4-1672-4ad7-83e6-a91a79e2e963?sessionId=fef3429c-4cff-4dcf-ac61-97cad81c2b8b', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "/site-packages/tornado/web.py", line 1790, in _execute
    result = await result
             ^^^^^^^^^^^^
  File "/jupyter_collaboration/projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py", line 210, in get
    return await super().get(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/site-packages/tornado/websocket.py", line 273, in get
    await self.ws_connection.accept_connection(self)
  File "/site-packages/tornado/websocket.py", line 863, in accept_connection
    await self._accept_connection(handler)
  File "/site-packages/tornado/websocket.py", line 946, in _accept_connection
    await self._receive_frame_loop()
  File "/site-packages/tornado/websocket.py", line 1105, in _receive_frame_loop
    self.handler.on_ws_connection_close(self.close_code, self.close_reason)
  File "/site-packages/tornado/websocket.py", line 571, in on_ws_connection_close
    self.on_connection_close()
  File "/site-packages/tornado/websocket.py", line 563, in on_connection_close
    self.on_close()
  File "/jupyter_collaboration/projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py", line 339, in on_close
    if isinstance(self.room, DocumentRoom) and self.room.clients == [self]:
                  ^^^^^^^^^
AttributeError: 'YDocWebSocketHandler' object has no attribute 'room'

This can be uncovered by adding the following pytest test:

@pytest.mark.parametrize("copy", [True, False])
async def test_get_document_notebook(rtc_create_notebook, jp_serverapp, copy):
    path, content = await rtc_create_notebook("test.ipynb", "test", store=True)
    collaboration = jp_serverapp.web_app.settings["jupyter_server_ydoc"]
    document = await collaboration.get_document(
        path=path, content_type="notebook", file_format="json", copy=copy
    )
    assert document.get() == content == "test"
    await collaboration.stop_extension()

krassowski avatar Jul 18 '24 09:07 krassowski

Note that the content ("test") is not a valid notebook. If I replace it with

nb = nbformat.v4.new_notebook()
content = nbformat.writes(nb, version=4)

then it does not throw. It looks like exception handling may be off here.

krassowski avatar Jul 18 '24 10:07 krassowski

Any progress on this? On a clean, fresh install of jupyterlab with python 3.12 with mambaforge, I basically can't open any existing notebooks as I get pages and pages of these errors. I had to uninstall the collab machinery entirely so I could at least get work done.

Given this is on a fully clean install on an otherwise empty system, I'm pretty concerned that it is likely to hit users very easily... And it's a hard blocker - nothing works, documents can't be opened, nor even closed: the UI hangs in a weird state.

fperez avatar Aug 22 '24 05:08 fperez

As per my previous reply, I think this error message is a red herring. It is basically error which shows up when the connection closes if there is a different error which lead to the connection closure. The immediate action item is to expose the real error so that we can address potentially multiple underlying problems. Do you also see this on newly created notebooks or only on existing notebooks? If it is the latter, can you share such an existing notebook?

I do not experience the problem you are facing but none of the deployments I manage use Python 3.12, and I am using the bleeding edge beta of version 3. I hope that with version 3/JupyterLab 4.3 - also in beta - many bugs will be ironed out to make it production-ready (for now I would not advise trying the beta yet - unless you have patience to follow some workarounds that I can share - as there are known issues in works).

krassowski avatar Aug 22 '24 06:08 krassowski

From using more RTC a bit more, I seem to be able to get a clean working setup when starting fresh and removing the .jupyter_ystore.db file at the location of the server. @fperez you may want to try removing that file and restarting the server.

martinRenou avatar Aug 22 '24 08:08 martinRenou

Mmh, on a completely clean install from scratch, made right now by downloading miniforge3 and adding my default packages, and after deleting the jupyter_ystore.db file at the root of the server, I get a completely non-functional Jupyter. It fails to open any existing notebook or to create any new one, always with the same error:

image

Basically (at least on this machine), the only way to use Jupyter for anything is to entirely remove jupyter-collaboration 2.1.0... I hope it's just a glitch on my machine (macOS 15.0.1, Firefox, all up to date), but if it's reproducible, it's pretty bad.

fperez avatar Oct 22 '24 20:10 fperez

@fperez I created an environment using your environment.yml using pixi, and everything seems to work fine:

pixi init --import environment.yml
pixi shell
jupyter lab

It's strange that you are mentioning jupyter-collaboration v2.1.0, because it should have installed v2.1.4. Could you try again?

davidbrochart avatar Oct 23 '24 07:10 davidbrochart

Ah, you may be onto something... It seems the culprit is a version pin in JupyterLab:

The following packages are incompatible
├─ jupyter-collaboration is installable with the potential options
│  ├─ jupyter-collaboration 2.1.4 would require
│  │  └─ jupyterlab >=4.0.5,<4.2 , which can be installed;
│  └─ jupyter-collaboration [1.0.0|1.0.1|...|2.1.3] conflicts with any installable versions previously reported;
└─ jupyterlab 4.2.5**  is not installable because it conflicts with any installable versions previously reported.

I had Lab 4.2.5, which kept me pinned at collab 2.1.0. I can't upgrade jupyter-collaboration to 2.1.4 without downgrading JupyterLab.

fperez avatar Oct 23 '24 16:10 fperez

I can confirm that once I allow the JuptyerLab downgrade to 4.1.8 and install collab 2.1.4, it works fine.

So whatever the bug was in collab was indeed fixed, thanks! The problem we have now is this version pin in JupyterLab, which may end up leaving users locked into an older version of collab with the bug.

Thanks for the pointer!

fperez avatar Oct 23 '24 16:10 fperez

It seems to be a conda issue, because with pip one can install jupyterlab==4.2.5 and jupyter-collaboration==2.1.4 in the same environment.

davidbrochart avatar Oct 24 '24 07:10 davidbrochart

I opened https://github.com/conda-forge/jupyter-collaboration-feedstock/pull/16.

davidbrochart avatar Oct 24 '24 07:10 davidbrochart

Actually conda-forge was doing the right thing. I released jupyter-collaboration v2.1.5 which fixes the issue.

davidbrochart avatar Oct 24 '24 08:10 davidbrochart

Awesome, thanks so much @davidbrochart!! Glad we tracked this down :)

fperez avatar Oct 24 '24 16:10 fperez

Thank you for reporting the issue!

davidbrochart avatar Oct 24 '24 16:10 davidbrochart