As there is not a lot of documentation about subscriptions I'd like to ask about a few things.
Is there any reconnection mechanism implemented? If it is, how does it work? Am I notified anyhow about reconnecting attempts?
If Apollo reconnects automatically, what happens with data that could be hypothetically emitted by the server during our _down time_? Does Apollo try to fetch it or do I have to manually fetch data after reconnection?
What happens if I subscribe to the same subscription many times? Is the same (socket?) connection reused, or each time there is a new connection created?
/label question
- Reconnection mechanism implemented?
No there is no reconnection mechanism, this is left up to you to decide how you want to reconnect. If there is something wrong with connection you should get com.apollographql.apollo.internal.subscription.SubscriptionManager.Callback#onNetworkError.
ApolloSubscriptionCall can be executed only once (after subscription is completed or canceled or failed) you can't execute more than once. You should call clone to get a new copy instance of original call to before re-trying to execute (similar to OkHttp.Call).
- What happens if I subscribe to the same subscription many times? Is the same (socket?) connection reused, or each time there is a new connection created?
Internally all subscriptions share the same socket. It will be auto closed after 10 seconds if there is no any active subscription left.
Thank you, it clear things up a lot for me. I think it should be placed somewhere in the wiki/README page as it's not obvious. For instance, from what I know Apollo for ios tries to reconnect automatically.
By the way, not to open another thread. What does com.apollographql.apollo.exception.ApolloCanceledException: Call is canceled. mean? I use Rx with Apollo, with automatical resubscription in case of an error. And I have my logcat spammed with that. Is it an Apollo issue, or server-side problem? Here is a full stack trace:
com.apollographql.apollo.exception.ApolloCanceledException: Call is cancelled.
at com.apollographql.apollo.internal.RealApolloSubscriptionCall.execute(RealApolloSubscriptionCall.java:45)
at com.apollographql.apollo.rx2.Rx2Apollo$4.subscribe(Rx2Apollo.java:151)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.Flowable.subscribe(Flowable.java:14426)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
You need to clone call before re-trying com.apollographql.apollo.ApolloCall#clone
Thanks for the tip, it helped me to find my bug. I used an Rx, and I forgot to defer my Flowables, so each time retryWhen was trying to resubscribe it used the old, _used_ call.
Thank you for your help. It's actually all I wanted to find out about subscriptions. You can close the issue or leave it open to make it visible for other users. Up to you.
@k-misztal I am having the same issue, would you care to share your solution, I am not very familiar with RxJava Flowables.
Most helpful comment
@k-misztal I am having the same issue, would you care to share your solution, I am not very familiar with RxJava Flowables.