-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trouble getting websocket to reopen for iOS or Android in KMM project #5633
Comments
Hi 👋 Thanks for sending this. Not getting a .reopenWhen { throwable, attempt ->
println("Reopening...")
delay(2000)
true
} I uploaded the reproducer here if you want to try. Is there any chance you can run your subscription through a proxy such as Charles? That would give more information what is happening. |
Hey @martinbonnin, thanks for the help. I checked out your test project and it works correctly for me too. And I did try to run Charles Proxy on iOS, but for some reason when I have the proxy connected, the websocket doesn't work at all. No websocket connection shows up and my app doesn't receive any subscription events. It's possible that I don't have something configured correctly in the Charles Proxy app, but I can see all the queries and mutations correctly. |
I added an iOS app to the reproducer (commit) and I can see the difference. Interestingly, I did not even get a call to When I enable wifi again, the subscription resumes though. Can you try with the sample, see if you can replicate your issue? Screen.Recording.2024-02-23.at.13.17.11.mov |
Thanks for adding an iOS project. For some reason, I'm not able to build it in Xcode on a device or in the simulator. Xcode won't let me select a device or simulator as if I don't have one that's compatible. It says "Any iOS Device (arm64)", but I have a new device running iOS 17.2 and the latest simulators. I'm using an Intel Mac still, so I don't know if that has something to do with it. Honestly, I didn't debug that very long because I assume if your sample project works for you it would work for me as well. I instead tried to replicate your setup within my own app. I wasn't previously using the SKIE library, and I was previously collecting the subscription |
Hey @martinbonnin, I got your demo iOS project running tonight. Just had to change the minimum deployment target to 17.0 for some reason even though my device is running 17.2. Regardless, I was able to confirm the same behavior you demonstrated on the simulator. The subscription worked fine initially, then when I disconnected the internet, I never observed Here's a snippet from the console logs. It looks like the websocket Task is finishing with an error immediately after the first time that
|
Hi @martinbonnin, have you had a chance to try running your demo iOS project on a device? I'm still struggling with this issue in our iOS app and I don't know if this is a bug and I should file a bug report or if I'm just misunderstanding how to setup my |
Thanks for trying out on a real device. This sounds like a bug I'll dig into it more this week, apologies for the delay! |
Thanks @martinbonnin. I was actually able to track down the bug and get it fixed! I'll file a bug report soon and describe all the details and the fix. I'm going to reference the demo project you created as a way to reproduce the bug. |
Closing as experimental WebSocketNetworkTransport is shipped as part of |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better. |
Question
I'm using Apollo in a multiplatform project for iOS and Android along with AWS AppSync with websocket communication. I can't get the websocket to reopen correctly on either platform after a temporary loss of internet connection.
I've setup several subscriptions using the
AppSyncWsProtocol
and everything seems to work correctly on both platforms. I can subscribe from either app and I receive subscription events as expected while the app is connected to the internet. However, if the app loses an internet connection, the websocket doesn't seem to get reopened as expected when internet is restored. I've experienced different issues on iOS and Android. On Android, I seem to have found a workaround, although I'm not sure if it will work in all cases.I've defined the
.reopenWhen
block when initializing theWebSocketNetworkTransport
and I'm also using the.retryWhen
block on my subscriptionFlows
. I'll first describe the issue I've faced with iOS, then I'll describe the issue I've faced on Android and my workaround for it.Here's an example of code in the shared module for initializing the
ApolloClient
and creating a subscription.From my reading of the source code, it seems that the
.reopenWhen
block should be executed repeatedly as long as it continues to returntrue
and the websocket is returning aNetworkError
. However, this isn't the behavior that I've observed on the iOS or Android apps. On iOS, if I return true from.reopenWhen
, it's only called one single time and the websocket never reconnects after the internet connection is restored. If I return false from.reopenWhen
, the error is passed along to the subscriptionFlow
which executes it's.retryWhen
block one single time and nothing else ever happens. However, if I return false from.reopenWhen
and then reestablish the internet connection before the delay in the.retryWhen
block expires, then the websocket will reconnect and theFlow
will start emitting again.On Android, I've been able to get the websocket to reconnect and get the subscription
Flows
to start emitting events again only by using a specific combination of.reopenWhen
and.retryWhen
. What I observed is that if.reopenWhen
returns true even one single time while the internet is still disconnected, then it will keep getting called endlessly with anUnknownHostException
over and over even after the internet is restored and the websocket will never reopen. If I use this crude workaround and only return true if I can successfully execute a query, then I can ultimately get the websocket to reopen.Returning false from
.reopenWhen
passes the error along to the subscriptionFlow
. The.retryWhen
block on the subscriptionFlow
executes which eventually causes.reopenWhen
to get called again in a loop until the internet is connected again, at which time,.reopenWhen
will return true, the websocket will get reconnected, and the subscriptionFlow
will start emitting again.So, I don't know if what I'm experiencing on iOS and/or Android is a bug or if I'm misunderstanding how I'm supposed to setup the
ApolloClient
to be able to gracefully reopen the websocket, but I need to be able to have my subscriptionFlows
survive temporary losses of network connection. Does anyone have an example of using Apollo with AWS AppSync and subscriptionFlows
where the reopening of the websocket is working?Tasks
The text was updated successfully, but these errors were encountered: