In my app I make synchronous PUT
requests using the Retrofit library. The problem is: sometimes the library throws EOFException
s.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With