Some users of my Android application are frequently running into a network error with the following error message: "Unexpected end of stream on null".
I didn't find any clear way to solve it by looking at other similar question. I haven't been able to reproduce the network error on my end.
1) I have unsuccessfully appended Connection=close
to the requests headers as this answer suggests
2) I have unsucessflly added .retryOnConnectionFailure(true)
as this answer suggests
3) I have unsuccessfully searched for a server side issue as this answer suggests but the requests with network issues are not appearing in the nginx access.log file
Here is how I init Retrofit
OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(40, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.build();
Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient);
this.retrofit = retrofitBuilder.build();
Here is my endpoint definition (in IUserService.java)
@POST("/v2/android/login/phone")
@Headers("Content-Type: application/json;charset=UTF-8;Connection=close")
Call<APIResult<Session>> phoneLogin(@Body APIRequest request);
And here is how the endpoint is queried
userService = retrofit.create(IUserService.class);
Call<APIResult<Session>> call = userService.phoneLogin(request);
call.enqueue(new GenericCallback<>(context, callback));
Our configuration:
Android (Java)
Retrofit 2.3.0: 'com.squareup.retrofit2:retrofit:2.3.0'
Okhttp 3.12.1: 'com.squareup.okhttp3:okhttp:3.12.1'
Server running on AWS Elastic Beanstalk, platform: Puma with Ruby 2.6 running on 64bit Amazon Linux/2.9.0
Can anyone explain better where the problem is coming from? Any idea how to reproduce this issue locally? Any way to solve this issue?