Skip to content

Realtime only has a single socket even with different endpointsΒ #102

@rrhett

Description

@rrhett

πŸ‘Ÿ Reproduction steps

  1. Create two Clients, and for each, create a Realtime.
  2. Attempt to subscribe on each, possibly to different things.

Explicit example:
val clientA = Client().setEndpoint("http://localhost:8080/v1").setProject("1234")
val clientB = Client().setEndpoint("http://localhost:8088/v1").setProject("5678")

val realtimeA = Realtime(clientA).subscribe(...)
val realtimeB = Realtime(clientB).subscribe(...)

πŸ‘ Expected behavior

It should create one socket per Client, or at most per endpointRealtime.

If I have multiple Client objects connected to different backends, I should be able to have a separate socket to each.

Simply changing

class Realtime ... {
  private companion object {
    private var socket: RealWebSocket? = null

to

    private val sockets: Map<String, RealWebSocket> = mutableMapOf()

and making appropriate thread-safe changes to the few places sockets are created/destroyed would address this.

πŸ‘Ž Actual Behavior

It shares a single socket across all Client/Realtimes, as it puts the socket on a private companion object.

Thus when I create realtimeB and call subscribe, it will close the socket, and create a new socket to localhost:8088 but try to merge all the requests for updates together. It's possible there are different users on each backend, etc.

🎲 Appwrite version

Version 1.8.x

πŸ’» Operating system

Linux

🧱 Your Environment

This is Kotlin using io.appwrite:sdk-for-android:11.4.0

Note that this is an unusual scenario to have multiple clients to multiple backends, but I'm designing a highly-resilient, client-driven multiple-backend project that can keep multiple backends in sync, so it's a requirement for my project.

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions