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

'YDocWebSocketHandler' object has no attribute 'room' #321

Open
martinRenou opened this issue Jul 2, 2024 · 18 comments
Open

'YDocWebSocketHandler' object has no attribute 'room' #321

martinRenou opened this issue Jul 2, 2024 · 18 comments
Assignees
Labels
bug Something isn't working

Comments

@martinRenou
Copy link
Member

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 martinRenou added the bug Something isn't working label Jul 2, 2024
@davidbrochart
Copy link
Collaborator

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

@martinRenou
Copy link
Member Author

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

@krassowski
Copy link
Member

krassowski commented Jul 16, 2024

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

@martinRenou
Copy link
Member Author

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

@krassowski
Copy link
Member

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
Copy link
Member

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.

@fperez
Copy link
Contributor

fperez commented Aug 22, 2024

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.

@krassowski
Copy link
Member

krassowski commented Aug 22, 2024

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).

@martinRenou
Copy link
Member Author

martinRenou commented Aug 22, 2024

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.

@fperez
Copy link
Contributor

fperez commented Oct 22, 2024

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.

@davidbrochart
Copy link
Collaborator

@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?

@fperez fperez self-assigned this Oct 23, 2024
@fperez
Copy link
Contributor

fperez commented Oct 23, 2024

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
Copy link
Contributor

fperez commented Oct 23, 2024

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!

@davidbrochart
Copy link
Collaborator

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
Copy link
Collaborator

@davidbrochart
Copy link
Collaborator

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

@fperez
Copy link
Contributor

fperez commented Oct 24, 2024

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

@davidbrochart
Copy link
Collaborator

Thank you for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants