My users from my app in production are complaining from an issue and it's been one week I'm trying to debug it to know if it's a problem in my code or a bug in Amplify.
I'm subscribing to a stream and the issue happens when I swipe the app away, switch the phone off, turn back on again and go back to the app. The subscription is still connected (I'm also listening to the Api Hub Channel) but stops receiving any event whatsoever.
I found #2918 mentioning that "the underlying websocket connection is not able to stay alive" when the app goes to the background. To deal with that I'm using AppLifecycleState to stop the subscription on paused and re-listen on resumed.
I gathered some info:
The issue is only happening in release mode in iOS on a physical device (prod users, ad hoc or TestFlight)
The issue is not consistently happening from the first try. Out of 20 times, I was able to reproduce it 17 times on the first try(background-phone off-phone on).
I noticed it happens fairly regularly when I switch the phone off, send an event (in my test, the subscription is onCreate), turn the phone back on and go back to the app.
No need to wait an amount of time in the background for the issue to arise.
If it didn't happen on the first try, it will on the second or third.
Now the most important thing to note: I noticed, while debugging it in debug mode (and using AmplifyLogger.verbose), that when I do the steps to reproduce it, the underlying WebSocketBloc receives a "UnsubscribeEvent" but it doesn't go all the way to "Closed subscription...." and I think this is where something is going wrong.
Let's say I switched the phone off and on 6 times. When I filter the logs for "subscription event", I get 6 events(expected). When I filter the logs for "closed subscription", I get 4(unexpected). It should be 5. A subscription was beginning to unsubscribe but stopped somehow.
Please find bellow a minimum reproducible example.
What's fascinating is that when I do the steps to reproduce, if I see the Connection Status in the example above, whenever I open the app back, go from "connecting" to "connected", I can receive new events. If I go back and it's directly "connected", no events are received anymore (hence my theory that a stream subscription was starting to cancel in the WebSocketBloc but stopped midway). Also if it stops receiving events and I stay in the app, I get the Timeout exception after some time from the stream and only after this exception that the status goes from "connected" to "disconnected".
Finally, in debug mode, I still see the WebSocketBloc not cancelling one of the subscriptions all the way but I still receive events no matter how many times I close the app.
This issue is affecting the most critical and core part of my app (this is the only place I'm using subscriptions) and more and more users are complaining from it since it will require them to close the app completely and reopen it again (a very bad user experience).
I tried to give as much details of my findings as possible. If something is not clear or not explained properly please let me know.
Thank you!
Categories
[ ] Analytics
[ ] API (REST)
[X] API (GraphQL)
[ ] Auth
[ ] Authenticator
[ ] DataStore
[ ] Notifications (Push)
[ ] Storage
Steps to Reproduce
Have a stream subscription listening to onCreate or onUpdate or both.
Listen to the AppLifecycle changes. (subscribe on resumed, unsubscribe on paused)
Swipe the app away to go back to the Home Screen of iOS.
Switch the phone off.
OPTIONAL (I felt that the issue happens more often with this step): Send an event depending on the stream subscribed to
Switch the phone on and go back to the app
No more new events are received after this point. (If events are received, repeat from step 3 to 6 until the issue arises)
Hi all, I'm going to close this issue for the lack of activity. If you're still experiencing this issue, please refer to the previous comment and we will reopen this given new feedback.
Description
Hi everyone!
My users from my app in production are complaining from an issue and it's been one week I'm trying to debug it to know if it's a problem in my code or a bug in Amplify.
I'm subscribing to a stream and the issue happens when I swipe the app away, switch the phone off, turn back on again and go back to the app. The subscription is still connected (I'm also listening to the Api Hub Channel) but stops receiving any event whatsoever.
I found #2918 mentioning that "the underlying websocket connection is not able to stay alive" when the app goes to the background. To deal with that I'm using AppLifecycleState to stop the subscription on paused and re-listen on resumed.
I gathered some info:
Please find bellow a minimum reproducible example.
Minimum reproducible example
```dart void main() async { WidgetsFlutterBinding.ensureInitialized(); AmplifyLogger().logLevel = LogLevel.verbose; await configureAmplify(); runApp(child: const DebugApp()); } FutureWhat's fascinating is that when I do the steps to reproduce, if I see the Connection Status in the example above, whenever I open the app back, go from "connecting" to "connected", I can receive new events. If I go back and it's directly "connected", no events are received anymore (hence my theory that a stream subscription was starting to cancel in the WebSocketBloc but stopped midway). Also if it stops receiving events and I stay in the app, I get the Timeout exception after some time from the stream and only after this exception that the status goes from "connected" to "disconnected".
Finally, in debug mode, I still see the WebSocketBloc not cancelling one of the subscriptions all the way but I still receive events no matter how many times I close the app.
This issue is affecting the most critical and core part of my app (this is the only place I'm using subscriptions) and more and more users are complaining from it since it will require them to close the app completely and reopen it again (a very bad user experience).
I tried to give as much details of my findings as possible. If something is not clear or not explained properly please let me know.
Thank you!
Categories
Steps to Reproduce
Screenshots
No response
Platforms
Flutter Version
3.13
Amplify Flutter Version
1.4.2
Deployment Method
Amplify CLI
Schema