I am using RxJava adapter of Retrofit to make API calls. I have implemented cancel request in onBackPressed of Activity so the call can get canceled when user tap the back:
client.dispatcher().cancelAll();
It does cancel all the request and my Rx also throws the correct exception. But when I open the activity again it takes about 1 minute delay before it process a API new request. Why is there a delay?
Just to confirm that I came to know that on unsubscribing the Rx, the adapter automatically cancels the requests. I have removed my manual cancelation code but still on subsequent API calls it takes about 1 minute to make a request.
To reproduce it, from MainActivity or MainViewModel make a call to API. Then during this period tap the screen back which will hide the activity in background and will also cancel the API request. Then bring the activity to foreground which will make an API call again. It will take about 1 minute delay to make a request.
Likely a problem with OkHttp, not Retrofit. Regardless: HTTP/1 or HTTP/2? Can you reproduce?
Yes, its reproducing every time in the way I have mentioned in my last comment. My test site is on HTTP/1.1.
good job man
As Jesse said, Retrofit doesn't make connections or anything鈥搃t delegates everything to OkHttp. If you can reproduce reliably with OkHttp directly please file a bug there.