27

In my app I make synchronous PUT requests using the Retrofit library. The problem is: sometimes the library throws EOFExceptions.

Below is a stack trace for one of such cases

29099-29269/com.mycompany.myapp D/Retrofit﹕ java.io.EOFException at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:192) at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:189) at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101) at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676) at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:426) at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:371) at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:466) at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73) at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38) at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321) at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240) at $Proxy7.addEvents(Native Method) at com.mycompany.myapp.api.MyService.addEvents(MyService.java:59) 

I tried the following prosposed solutions but none of them helped in my case:

Here is how I create RestAdapter in my app:

OkHttpClient okHttpClient = new OkHttpClient(); RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(Url) .setRequestInterceptor(new RequestInterceptor() { @Override public void intercept(RequestFacade request) { request.addHeader("Accept", "application/json"); request.addHeader("Content-Type", "application/json"); } }) .setClient(new OkClient(okHttpClient)) .setLogLevel(RestAdapter.LogLevel.FULL) .setErrorHandler(new MyErrorHandler()) .build(); 

Does any one know an other solution for the problem?

Btw, I can't use solutions involving System.setProperty("http.keepAlive", "false"); because I need to keep my connection alive because of performance reasons.

6
  • Is the server returning a 204 for you? Commented Nov 20, 2014 at 11:15
  • Did you manage to solve the problem? Similar is discussed in issue #1114 of OkHttp. Commented Jan 6, 2015 at 11:15
  • @JJD No I did not solve the problem. Commented Jan 6, 2015 at 17:51
  • @Bobrovsky I posted my setup in the Retrofit issue #397 you linked yesterday. Maybe it is of help for you. Commented Jan 7, 2015 at 9:02
  • Did you use last version of okhttp? Commented Feb 5, 2015 at 15:08

3 Answers 3

2

This issue can commonly be caused by a network error. If it is reproducing consistently, consider the potential cause of content length and request timeout. Sometimes timed out network requests can return an improper End of File. Which would throw this error as a result.

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps EOF as lost network connection or timed out. Try increasing your timeout and ensuring keep-alive is set.

Comments

0

You can look at this answer with similar problem.

If you are with big requests (i think this is more than 50Mb of data) and you are not using pagination system in the server side, you can get this type of error.

Also it can be a TimeOut of the server side, for example.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.