Skip to content

Resources subscribed over websocket never unsubscribed [Optimization] #311

Description

@adileo

It looks like that store.unSubscribeWebSocket is never called.

This means that the client once a hook like useResource is used it will keep listening over websocket for updates that no one reads.

Fix proposal:

  • within store.unsubscribe() check if callbackArray is empty then trigger a store.unSubscribeWebSocket

Any side issues that could arise from this?

Activity

  1. joepio commented on Mar 4, 2023

    @joepio
    Member

    Thanks for the suggestion!

    Some time ago, this was the actual behavior. However, this had the following issue:

    • View a resource X. The client subscribes to changes for X.
    • Hide resource X (e.g. open resource Y). The websocket now also unsubscribes to updates from X.
    • Have some other client make changes to resource X. These changes are not sent to the client.
    • Open resource X again. Now it will show an outdated version, because it did not see older items. The client does not know it needs to update.

    We can deal with this in two ways:

    • Always re-fetch the resource when rendering it in the DOM. This can be very costly, and will result in a lot of requests.
    • Keep subscriptions open for all shown resources (current implementation). This sometimes leads to irrelevant Commits being sent and parsed, but as long as clients once in a while re-load their store (e.g. by refreshing the page) that is a small price to pay.

    So unfortunately, I think it's better to keep things the way they are now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions