Back

[SOLVED] Unable to establish a realtime subscription connection

  • 0
  • Flutter
  • Cloud
fernandoxlr
30 Sep, 2023, 22:47

I have a document that is the user profile. I try to subscribe to any changes by doing:

TypeScript
var s = realtime.subscribe(['databases.app.collections.profile.documents.${_social.awAccount!.$id}']);
    s.stream.listen((event) {
      Log.w(event.toString());
    }, onError: (a) {
      Log.e(a.toString());
    }, onDone: () {
      Log.e('profile connection closed');
    });

I have another use case: subscribing to a chat collection, where a document is a chat message:

TypeScript
realtime.subscribe(['databases.chat.collections.${widget.group}.documents']);

After cloud upgrade I've been getting the streams to call onDone and connection is lost. I've just noticed this issue recently, because the users are complaining about chat connection issue.

The users have permission to that document and collection. The users can do database.listDocuments for chat collection, so they really have permission.

I am using the current flutter sdk 11.0.0 and appwrite cloud. I read the docs again, and I couldn't figure out if anything was changed from previous sdk version. The problem is occurring in both Android and iOS devices, in different networks (wifi, 5g)

The logs for the chat code:

TypeScript
subscription: wss://cloud.appwrite.io/v1/realtime?project=REALPROJECTID&channels%5B%5D=databases.chat.collections.k82rekh0jl9zrep.documents
[chat] Connection closed

Also tried ending with documents.* but no success.

TL;DR
The user was experiencing issues with establishing a realtime subscription connection in their app. However, the issue has been solved and the chat function is now working properly. It was discovered that the problem occurred when trying to subscribe to both a profile document and a chat collection simultaneously. The solution was to subscribe to only one channel at a time. The user also tried using wildcards in their subscription, but this is not allowed for realtime channels. They were advised to use different instances of realtime for each subscription. The issue was occurring on both Android and iOS devices, on different networks. The logs showed that the connection was being closed after establishing the subscription.
Drake
30 Sep, 2023, 23:00
  • is not allowed for realtime channels.

Are you using multiple instances of realtime?

fernandoxlr
30 Sep, 2023, 23:19

No, same instance. I cut the url to be short, but both subscriptions are shown in that log. I tried subscribing just one example or another, and I have same result.

What do you mean with "is not allowed for realtime channels"? Is it * ?

Drake
30 Sep, 2023, 23:21

I mean the list of valid channels are here: https://appwrite.io/docs/apis/realtime#channels and you must use an ID. You can't use wildcards

Drake
30 Sep, 2023, 23:21

Try using different realtime instances for each subscription

fernandoxlr
30 Sep, 2023, 23:28

It was just a try. But the current code doesn't use wild card.

fernandoxlr
30 Sep, 2023, 23:28
TypeScript
realtime.subscribe(['databases.chat.collections.${widget.group}.documents']);

Result: databases.chat.collections.k82rekh0jl9zrep.documents

fernandoxlr
30 Sep, 2023, 23:29

This was working before, users could chat in real time, by receiving the messages in that collection.

fernandoxlr
30 Sep, 2023, 23:30

I tried, same problem.

Drake
30 Sep, 2023, 23:34

When does the disconnect happen?

fernandoxlr
30 Sep, 2023, 23:37

About 1 second after subscription.

Drake
30 Sep, 2023, 23:40

Interesting... What if you only subscribe once?

fernandoxlr
30 Sep, 2023, 23:42

Do you mean, subscribe only one channel? I'm doing that already. I have removed the profile subscription. Actually I tried to subscribe just profile doc, and just chat collection's docs to test, but I have the same connection issue in both cases.

Drake
30 Sep, 2023, 23:42

One subscription

fernandoxlr
30 Sep, 2023, 23:48

Yes, I meant that. One subscription

Drake
1 Oct, 2023, 03:15

One subscription to profile doc only and no other realtime subscriptions, right?

fernandoxlr
1 Oct, 2023, 12:51

Yes. I removed the other one to test. And the same disconnection happens.

fernandoxlr
1 Oct, 2023, 12:52

And if I try to get the document (or the list of documents) it works normally.

Drake
1 Oct, 2023, 15:52

You mean databases.getDocument() or databases.listDocuments()?

Drake
1 Oct, 2023, 23:58

@fernandoxlr so there was a problem with realtime but it should be fixed now. Are you still seeing the problem?

fernandoxlr
1 Oct, 2023, 23:58

Oh, good to know πŸ™Œ

fernandoxlr
1 Oct, 2023, 23:59

Yeah, it seems to be working now πŸ˜„

fernandoxlr
2 Oct, 2023, 00:00

The chat function in my app is back

fernandoxlr
2 Oct, 2023, 13:50

[SOLVED] Unable to establish a realtime subscription connection

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more