Back

SOLVED: Realtime Issue with Flutter - Subscription auto expires

  • 0
  • Self Hosted
  • Flutter
  • Realtime
corax
7 Aug, 2023, 10:09

Hi,

After upgrading Flutter Appwrite from version 8.2.0 to 9.0.1, I have faced these issues...

First Issue was, I was using single Realtime instance for creating all the subscriptions for multiple channels but on 9.0.1 when I tried to subscribe to multiple channels the subscription gets set to 'subscriptions:null' automatically when the second channel was added. Basically it was setting and cancelling the subscription when I added the second channel.

but, I found a solution for this issue and used different realtime instances for each channel/subscription and it worked. Seems like one realtime instance can handle only one channel in the 9.0.1 version, in 8.2.0 I could subscribe to multiple channel using one instance of Realtime.

So Basically, its working fine now but the new issue I am facing regarding this is that For example, I subscribe to a 'test' channel it works okay and I get updated but after some time maybe (4-5 minutes or more) the updates from realtime stops as if the connection is closed and when in that scenario i try to cancel or close the realtimesubscription it gives me the error

'Null check operator used on a null value' From this part of the code:

'realtime_mixin.dart' Line 141: "_channels[channel]!.remove(controller);"

I would like to know if there is any timeout limit for realtimesubscription that I am not aware of so I can change it.

My Appwrite backend is hosted on Apache Server.

TL;DR
TL;DR: The original issue of a Realtime problem with Flutter has been solved. The user faced issues after migrating to a new version and encountered errors when uploading functions. The user also experienced lag and slowness with Apache web server when using a reverse proxy to connect to Appwrite. The solution was to change the Apache Timeout directive. However, there is still an issue with Realtime subscriptions where the connection is automatically closed after a period of inactivity. The user is seeking information on a timeout limit for realtimesubscription.
Drake
7 Aug, 2023, 21:27

Known issue: https://github.com/appwrite/sdk-for-flutter/issues/156. maybe you can use different realtime stances for now? or downgrade?

corax
8 Aug, 2023, 12:25

I am using different instances of realtime for now, it works but the new problem is if the connection is idle (received no update) it is closed auto after that no updates are received

Drake
8 Aug, 2023, 15:59

Your apache server probably has a timeout on connections. You'll need to find out the directive to set the timeout for websocket connections

corax
9 Aug, 2023, 14:22

Timeout is not the issue here I guess, I have a web site with realtime too but that works fine without any connection issues.

But, I will still look into apache side again in timeout case.

corax
1 Sep, 2023, 21:35

Hello @Steven ,

I have changed Apache Timeout directive it actually works and realtime does not disconnect.

But, when I access my appwrite backend directly using the actual port where it is hosted then again it still disconnects realtime without any reverse proxy in between. A clear cut direct connection to Appwrite but it still disconnects. Version 1.3.8

Although in version 1.3.4 It seemed okay (Or maybe using one realtime instance kept the socket alive on adding and removing channels)

TypeScript

I have tried to add varnish cache control, but it doesn't work.

Thanks, Rehan

Drake
1 Sep, 2023, 21:57

how long before disconnect? is this a mobile app? is it in the foreground the whole time wiht the screen on?

corax
1 Sep, 2023, 22:08

It is a mobile app yes, yes It is in the foreground with the screen on, Although I will confirm on the time.

Can you please let me know something about Apache Lag issue?

Drake
1 Sep, 2023, 22:10

sorry, dunno about apache

corax
1 Sep, 2023, 22:11

Hmm alright, not sure why so much lag for using reverse proxy

corax
1 Sep, 2023, 22:18

Well, timeout on direct connection to Appwrite which is direct to Traefik is more than 5-6 minutes

Drake
1 Sep, 2023, 22:34

but through apache it's longer?

corax
2 Sep, 2023, 07:38

On apache it depends on Timeout directive

corax
2 Sep, 2023, 08:09

Also can you please tell me why I am seeing this error

corax
2 Sep, 2023, 11:13

Also please resolve this Flutter SDK realtime issue. Where we have to use different Realtime Instances. They open up multiple connections to Appwrite from one device which I think is not good.

corax
2 Sep, 2023, 17:04

@Steven I need urgent support from a Core person understanding of Appwrite and urgently

corax
2 Sep, 2023, 17:09

Yes I worked on that, I need urgent help with something else. I have migrated from 1.3.8 to 1.4.1 and I can not upload functions anymore.

Getting this error in image. then I tried to migrate back to 1.3.8 and it Failed with error and Functions show 500 in console and then migrated back to 1.4.1 but I can not upload functions because of this error. @Steven

corax
4 Sep, 2023, 17:49

SOLVED: Realtime Issue with Flutter - Subscription auto expires

Drake
4 Sep, 2023, 18:08

we need to push a release to fix https://github.com/appwrite/appwrite/pull/6095

corax
4 Sep, 2023, 18:44

Okay, although I did that change and is now using custom image for now. Should I remove SOLVED?

Drake
4 Sep, 2023, 19:20

no because the original problem was solved

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