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

Can not close awareness listener when call provider.destory() #150

Open
2 tasks done
orangejava opened this issue Aug 31, 2023 — with Huly for GitHub · 2 comments
Open
2 tasks done

Can not close awareness listener when call provider.destory() #150

orangejava opened this issue Aug 31, 2023 — with Huly for GitHub · 2 comments
Assignees
Labels
bug Something isn't working

Comments

Copy link

orangejava commented Aug 31, 2023

Please save me some time and use the following template. In 90% of all issues I can't reproduce the problem because I don't know what exactly you are doing, in which environment, or which y-* version is responsible. Just use the following template even if you think the problem is obvious.

Checklist

Describe the bug I use a rich text editor with collaborative editing named Textbus, it use yjs and y-websocket to complete collaborative function. I use this editor with y-websocket and deploy a y-websocket node server. Open the editor it will new WebsocketProvider. When more than two users edit together( A and B), it collaborate normally; when A user click v button, A user will disconnect the y-websocket and the editor will destroy, I call the provider.destroy() to disconnect the y-websocket at the same time, A user and B user disconnect the collaborative, but in the Browser console, I see the A and B still print the awareness info, the correct should B print A not. The provider.awareness is not destroy completely, it cause the two provider.awareness send the message to other user client when A user connect to the editor again. I call the provider.awareness.destroy() to close the awareness update, it should add this statement (provider.awareness.destroy()) in the provider.destroy() function or modify the awareness.off() function.

To Reproduce Steps to reproduce the behavior:

  1. open the two different account with the same editor
  2. Click a button and call provider.destroy() to disconnect the y-websocket connection.
  3. Open console, you will see the provider.awareness is still send message.
  4. When this editor is reconnect the y-websocket, it will exist two provider.awareness send message.

Expected behavior When user call the provider.destroy() the provider should be destroyed completely includes awareness.

Screenshots I'm sorry for this, due to the network limitation, I cannot provide the screenshots temporarily.

Environment Information

  • Chrome / Node.js (v18.16.1) [e.g. Chrome, Firefox, Node.js]
  • yjs v13.5.52, y-websocket v1.4.5.

Additional context Add any other context about the problem here.

Huly®: YJS-569

@orangejava orangejava added the bug Something isn't working label Aug 31, 2023
@a3626a
Copy link

a3626a commented Mar 15, 2024

I think we are facing same issue.

Awarness is not removed when destroy is called. Awareness is removed only when the tab is closed

But I'm not sure this is a feature or a bug.

@dmonad
Copy link
Member

dmonad commented Apr 16, 2024

When the provider is destroyed, it doesn't destroy the awareness instance. This is the intended behavior because other parts of your software may rely on the awareness instance.

If the awareness changes (e.g. moving of a cursor), is still propagated over y-websocket after calling provider.destroy(), this would be a bug. But I don't think this is the case here.

If you do awarenes.on('update', () => { console.log('update') }), you will receive updates forever, unless you destroy the awareness instance. It's not bound to the provider instance.

Special case: the awareness instance is destroyed when the associated ydoc is destroyed.

You can also call awareness.destroy() manually, if that is something you want to do.

However, I don't want to destroy the awareness instance when provider.destroy is called, because other providers may still use the awareness instance. Awareness instances can be shared between providers.

Just make sure that you don't use old awareness instances. Alternatively, you can supply awareness as an option to the WebsocketProvider, so the instance doesn't change when you recreate the provider. See https://github.com/yjs/y-websocket/?tab=readme-ov-file#api

In any case, I recommend that you do provider.disconnect instead of provider.destroy and recreating a provider.

@dmonad dmonad closed this as completed Apr 16, 2024
@huly-for-github huly-for-github bot reopened this Apr 17, 2024
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

3 participants