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

WebsocketProvider not destroyed #636

Closed
lin52025iq opened this issue Jun 20, 2023 · 5 comments
Closed

WebsocketProvider not destroyed #636

lin52025iq opened this issue Jun 20, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@lin52025iq
Copy link
Contributor

Description
HocuspocusProviderWebsocket is not destroyed when HocuspocusProvider's destroy is called.

Steps to reproduce the bug
Steps to reproduce the behavior:

// init provider
const socket = new HocuspocusProviderWebsocket({
  url: 'ws://127.0.0.1:1234',
})

const provider = new HocuspocusProvider({
  websocketProvider: socket,
  name: 'hocuspocus-demo',
  broadcast: false,
})

// do
provider.destory()

// result: the status of websocket alreadly is pending,

Expected behavior
HocuspocusProviderWebsocket is destroyed

Screenshot, video, or GIF
If applicable, add screenshots to help explain your problem.

Environment?

  • operating system: all
  • browser: yes
  • mobile/desktop: all
  • Hocuspocus version: 2.1.0

Additional context
Add any other context about the problem here.

@lin52025iq lin52025iq added the bug Something isn't working label Jun 20, 2023
@georeith
Copy link
Collaborator

+1 I've been meaning to make a ticket about this, I'm manually destroying the websocket provider at the same time in our application.

@lin52025iq
Copy link
Contributor Author

I think the problem in here.
#637

image

@janthurau
Copy link
Collaborator

janthurau commented Jun 21, 2023

hmm yep we're still lacking documentation for this unfortunately. It's intended behavior as the socket can be created without a document connected/connecting (and should survive a document being destroyed as you can just open another one)

If you want to close the connection, you need to destroy the websocket provider as well (socket.disconnect() or socket.destroy()). Documentation is in the process ..

@romansp
Copy link

romansp commented Jun 28, 2023

I agree with the intended behavior described above but I noticed something else that seems unexpected.

I'm reusing single HocuspocusProviderWebsocket across multiple HocuspocusProvider instances and then manually destroy these when required (onBeforeUnmount hook in Vue). But it seems that provider doesn't unsubscribe properly from websocketProvider which leads to a memory leak.

For example, onStatus hook will still be called for websocket reconnect events later even after HocuspocusProvider has been explicitly destroyed.

Here handler is configured, but this.removeAllListeners() in destroy call won't unsubscribe this.

this.configuration.websocketProvider.on('status', this.onStatus.bind(this))

Will try to provide a minimal repro soon.

@janthurau
Copy link
Collaborator

Closing this, as the behaviour is intended. The memory leak has already been fixed by @raineorshine :)

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