General description
When I'm sending several requests in a short time, some of them are never getting response or error.
API
I've got an singleton class that keeps retrofit service in it. I use this class to perform all calls to api, every call returns Observable with some kind data.
public class CoreApi {
public static final String BASE_URL = "https://www.example.com/";
private static CoreApi instance;
private CoreApiService service;
public static CoreApi get() {
if (instance == null)
instance = new CoreApi();
retrun instance;
}
private CoreApi() {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
if (BuildConfig.DEBUG)
httpClient.addInterceptor(httpLoggingInterceptor);
httpClient.connectTimeout(60, TimeUnit.SECONDS);
httpClient.readTimeout(60, TimeUnit.SECONDS);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxErrorHandlingCallAdapterFactory.create())
.client(httpClient.build());
service = (builder.build()).create(CoreApiService.class);
}
public Observable<SomeData> getSomedata(String authorization) {
return service.getSomeData(authorization);
}
}
SERVICE
interface CoreApiService {
@GET("someDataEndpoint/")
Observable<SomeData> getSomeData(@Header("Authorization") String authorizationToken);
}
CALL
I've setup a button in activity that everytime it is clicked, it performs call to api:
Button button = (Button) findViewById(R.id.test_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CoreApi.get().getSomeData("JWT thisisexampletokenreplacedforthesakeofthisquestion")
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe(new Action1<SomeData>() {
@Override
public void call(SomeData someData) {
// operations are performed on data, irrelevant for the issue as even if I comment them the issue still occurs
}
});
}
});
ISSUE
Whenever I click on the button(not too fast), in logs I can see that the request is being made by retrofit.
But when I start to click the button a little bit faster, I can see in logs that requests are being send, but not all of them receive the response. Theres no error, theres no timeout, theres nothing. In logcat I can only see that the request have been made(see below).
09-19 11:26:05.421 18763-18821/com.myapp.app D/OkHttp: --> GET https://www.example.com/someDataEndpoint/ http/1.1
09-19 11:26:05.421 18763-18821/com.myapp.app D/OkHttp: Authorization: JWT thisisexampletokenreplacedforthesakeofthisquestion
09-19 11:26:05.422 18763-18821/com.myapp.app D/OkHttp: --> END GET
SUMMARY
The example above is simplified, but this issue occurs only when there are a lot of calls in a short time(not necessarily to the same endpoint).
At first I noticed it when my HandlerThread responsible of refreshing user data from several endpoint in a specified sequence started to getting stuck in random points, sometimes at 2nd, sometimes at 10th call and sometimes somewhere in between. Weird thing is that after one of those calls gets stuck, I can still perform other calls from other places in application.