Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOFException in RealBufferedSource.readUtf8LineStrict(): 0-bytes in stream #1517

Closed
swankjesse opened this issue Mar 19, 2015 · 79 comments
Closed
Labels
bug Bug in existing code

Comments

@swankjesse
Copy link
Collaborator

We're getting an EOF exception with size=0 in the stream.

java.io.EOFException: \n not found: size=0 content=...
            at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:200)
            at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:187)
            at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
            at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:791)
            at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:90)

(Forked from issue 1114.)

@simtse
Copy link

simtse commented Apr 1, 2015

@swankjesse mentioned the following

My hypothesis is that these are just badly-behaving webservers, or proxy servers or something. In OkHttp 2.3 we're now including more information about the connection when this problem occurs. This happens to normal devices, like your Moto X 2014.

So this is the problem that I am running into and it doesn't seem to be the other issue [https://github.com//issues/1518] related to corruption of data. @swankjesse , if you think it is the webserver, do you know what on the server might trigger this only a 5-10% of the time or maybe even less? Most of the time it works, but once in a while I get this response.

@swankjesse
Copy link
Collaborator Author

@simtse what device are you using?

@simtse
Copy link

simtse commented Apr 1, 2015

We are using Nexus 4, Nexus 5, Samsung Galaxy S4, Galaxy Note 3, OnePlus One, Nexus 9, HTC One M7, HTC One S, HTC One One X, Moto X 2013. Those are the ones we use most often.

@swankjesse swankjesse added the bug Bug in existing code label Apr 19, 2015
@swankjesse swankjesse added this to the 2.5 milestone Apr 19, 2015
@iglaweb
Copy link

iglaweb commented May 2, 2015

Getting this issue on Huawei P6-U06 4.2.2. The problem seems to appear quite often only while downloading large files e.g. 600 Mb. The only solution is to make a connection retry?(
I'am using a GET request.

@aniketalhat
Copy link

Hi,

I am facing this issue during low traffic time, I have 24 threads connected to the influxdb server making batch/sec updates. Little insight might help.
Caused by: retrofit.RetrofitError: unexpected end of stream on Connection{:8086, proxy=DIRECT hostAddress= cipherSuite=none protocol=http/1.1} (recycle count=0)
at retrofit.RetrofitError.networkError(RetrofitError.java:27)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at org.influxdb.impl.$Proxy5.write(Unknown Source) ~[na:na]
at org.influxdb.impl.InfluxDBImpl.write(InfluxDBImpl.java:126)
at
... 21 common frames omitted
Caused by: java.io.IOException: unexpected end of stream on Connection{:8086, proxy=DIRECT hostAddress=influxdb cipherSuite=none protocol=http/1.1} (recycle count=0)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:211)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:917)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)
at com.squareup.okhttp.Call.getResponse(Call.java:274)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201
at com.squareup.okhttp.Call.execute(Call.java:81)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
... 25 common frames omitted
Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:200)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
... 36 common frames omitted

@ivamluz
Copy link

ivamluz commented Jul 9, 2015

Hi guys,

Are you aware of any workaround possible? The issue doesn't seem to happen on Android 5.0.2, but happens quite often on 4.1.2 and 4.1.4 (at least).

Thanks,
Ivam

@GBouerat
Copy link

Same issue here,
IOException is thrown in 3 ms every 10, 20 or 30 requests ...

OkHttpClient client = new OkHttpClient();
client.setRetryOnConnectionFailure(false);
HttpURLConnection connection = new OkUrlFactory(client).open(url);

It never happens with okhttp include in Lollipop.

@swankjesse
Copy link
Collaborator Author

Running into this issue? Please send me a test case!

@swankjesse swankjesse modified the milestones: Icebox, 2.5 Aug 1, 2015
@dmoneyUK
Copy link

I recreated this issue on OkHttp 2.4.0 in debug. I set a break point on the line "Response response = getResponse().getResponse();" in the HttpURLConnectionImpl# getHeaders() method. My tomcat server is configured connectionTimeout="10000" for SSL connector. So, if I hold the getHeaders() method and let the server to close the connection. The client side always complains:

"org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://xxx.xxx.xxx.xxx/myapplication/api/myservice": unexpected end of stream on Connection{xxx.xxx.xxx.xxx:443, proxy=DIRECT@ hostAddress=xxx.xxx.xxx.xxx cipherSuite=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA protocol=http/1.1} (recycle count=3); nested exception is java.io.IOException: unexpected end of stream on Connection{xxx.xxx.xxx.xxx:443, proxy=DIRECT@ hostAddress=xxx.xxx.xxx.xxx cipherSuite=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA protocol=http/1.1} (recycle count=3)
...
Caused by: java.io.IOException: unexpected end of stream on Connection{xxx.xxx.xxx.xxx:443, proxy=DIRECT@ hostAddress=xxx.xxx.xxx.xxx cipherSuite=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA protocol=http/1.1} (recycle count=3)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:211)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:917)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:793)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:439)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:384)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getHeaders(HttpURLConnectionImpl.java:150)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getHeaderFieldKey(HttpURLConnectionImpl.java:202)
at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getHeaderFieldKey(DelegatingHttpsURLConnection.java:202)
at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getHeaderFieldKey(HttpsURLConnectionImpl.java:25)
at org.springframework.http.client.SimpleClientHttpResponse.getHeaders(SimpleClientHttpResponse.java:92)
... 9 common frames omitted

Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:200)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
... 27 common frames omitted

I cannot image any reason that would cause the client spend more than 10s to read the response. Any idea?

@swankjesse
Copy link
Collaborator Author

@dmoneyUK could you isolate this into a test case? There's lots of examples in CallTest, and MockWebServer is pretty capable around setting up timeouts etc.

@sylvia43
Copy link

I'm getting the same problem while creating a Websocket: http://stackoverflow.com/questions/32161398/okhttp-websocket-unexpected-end-of-steam-on-connection

EDIT: Figured it out. The server was closing the connection and not sending any data back, due to a misconfiguration on my part. That said, maybe there could be a way to make that error clearer for the developer?

@dmoneyUK
Copy link

@anubiann00b In my case, the "Unexpected end of stream" was also caused by server's connection timeout. But the question why does the client spend so much time to read a simple response? My server side timeout is 10 second, and the request was not a file upload/download, it is supposed to complete in 1 second at most. I cannot find any log in server side showing the request is received.

@dmoneyUK
Copy link

@swankjesse Is there anyway to turn the okhttp log to debug level? In my case, the client spend too much time to read a simple response and server's connection timeout. i did not find any information about what happened there.

@swankjesse
Copy link
Collaborator Author

@dmoneyUK I recommend you try out https://charlesproxy.com to inspect your HTTP traffic. We may add trace logging to OkHttp, but we don't have it currently.

@dmoneyUK
Copy link

Hi, I found 90% of this kind of exceptions happening in my environment are from "GET" request. And I found a code block in httpengine as below:

 private Connection createNextConnection() throws RouteException {
 ConnectionPool pool = client.getConnectionPool();

// Always prefer pooled connections over new connections.
for (Connection pooled; (pooled = pool.get(address)) != null; ) {
  if (networkRequest.method().equals("GET") || Internal.instance.isReadable(pooled)) {
    return pooled;
  }
  closeQuietly(pooled.getSocket());
}
....
}

Can you tell me why the GET request does not need to check connection readable?

@swankjesse
Copy link
Collaborator Author

@dmoneyUK OkHttp can silently recover from those GET failures, and it’s more efficient to try and recover vs. test first. (The API to check whether a connection is readable is a bit of a hack!)

@GBouerat
Copy link

Still present in version 2.5.0 ...

with connection.setRequestProperty("Connection", "close"); there is no more errors, but it's not a valid solution ...

@dmoneyUK
Copy link

I solved this In my envrionment. In my case, when OkHttp tries to re-use a connection which has been closed by my tomcat server, the exception happens. My solution is to configure the tomcat server's "keepAliveTimeout" > than the client's connection timeout so that the server will never close a connection before the client.

Thanks @JakeWharton

@ZeWaren
Copy link

ZeWaren commented Sep 29, 2015

If you called setRetryOnConnectionFailure(false); on your connection, you will never have a solution to prevent those i/o errors.

Java's sockets have per design no way of knowing TCP connections are in state CLOSE_WAIT without trying to read from them.

OkHTTP or whatever library you use will send data into the closed connection, try to read from it, (only then) realize that it was closed, open/use another one and send the request again.

Configuring a very long Keep-Alive duration on your servers will prevent most of the errors, but if your clients are behind any kind of proxies, your configuration won't be relevant anymore.
Also, if your servers handle many requests and connection, the ops team that configures your front servers might not like the ideas of having tens thousands of unused opened connections.

@jeaking
Copy link

jeaking commented Oct 13, 2015

@swankjesse Do you think adding isReadable() check for GET request while retryOnConnectionFailure is set to false is good idea?

@doridori
Copy link

doridori commented Dec 3, 2015

Im getting this on ~1/6 calls using POST

Caused by: java.io.EOFException: \n not found: size=0 content=...

If I do the post via curl all is fine...this on okhttp 2.6.0 on android 6.0

@lexius
Copy link

lexius commented Dec 8, 2015

The same error here.

 java.io.IOException: unexpected end of stream on Connection{192.168.10.22:443, proxy=DIRECT@ hostAddress=192.168.10.22 cipherSuite=TLS_RSA_WITH_AES_128_CBC_SHA protocol=http/1.1} (recycle count=0)
 Caused by: java.io.EOFException: \n not found: size=0 content=...
                                                                          at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)

On okhttp 2.6.0 and android 6.0

@laalto
Copy link

laalto commented Dec 9, 2015

I get this problem consistently on one particular REST service. PUT and DELETE requests fail with this error while GET on the same service works just fine and other services in the same network environment work with no problems.

The same PUT/DELETE also go through successfully when run through Charles Proxy in SSL proxying mode.

Tracing with Wireshark shows the following, comparing to the trace from the proxied request that works:

  • Much more TLS application data being sent with less intermediate ACKs (resends?)
  • Eventually the server RSTs the connection and the 5 outstanding app data packets get RST,ACK

I don't know if it makes a difference but the URL is about 5500 bytes in size - a very long identifier embedded in it. In GET with this service endpoint the URLs are only around 660 bytes i.e. well below what fits in one packet.

Android versions 4.x-6.0, many devices including plain x86_64 6.0 emulator, OkHttp 2.5.0 and 2.6.0.

@laalto
Copy link

laalto commented Dec 9, 2015

Ok, did an experiment and shortened the requestLine by replacing the 5+kB identifier with a shorter one "foo". The request went through all right and got the expected error message from backend. So maybe it's about the way long request lines are written out i.e. not waiting for ACKs before proceeding, and then a server-side component backs off rapidly. I'll contact the network infra people to see if there's some e.g. DoS prevention in load balancers/proxies here.

@stepheaw
Copy link

stepheaw commented Dec 5, 2017

@crossle did you fix the issue?

@sschuberth
Copy link
Contributor

sschuberth commented Jan 30, 2018

The issue can be easily reproduced by trying to download a source artifact from SourceForge, like https://master.dl.sourceforge.net/project/tyrex/tyrex/Tyrex%201.0.1/tyrex-1.0.1-src.tgz. Neither adding .addHeader("Connection", "close") to the request nor adding .retryOnConnectionFailure(true) to the client helps.

Given how big of a site SourceForge is, even if it was a server configuration issue, can we reopen this to track adding a work-around, @swankjesse? Also, I have no issues downloading that file with Firefox or curl.

EDIT: Turns out the problem with downloading from SourceForge can be avoided by upgrading to at least java 8u161.

@herusdianto
Copy link

Hi, anyone have solution for this problem?

@Kolyall
Copy link

Kolyall commented Feb 15, 2018

How to resolve the issue?

java.io.IOException: unexpected end of stream on Connection{develop.by:8000, proxy=DIRECT@ hostAddress=develop.by/195.***.***.**:8000 cipherSuite=none protocol=http/1.1}
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:205)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.EOFException: \n not found: limit=0 content=…
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:227)
    at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:212)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
	... 19 more

Code:

final Request request = new Request.Builder()
              .get()
              .url("http://develop.by:8000")
             .build();

OkHttpClient okHttpClient = new OkHttpClient.Builder()
              .readTimeout(30, TimeUnit.SECONDS)
              .writeTimeout(30, TimeUnit.SECONDS)
              .build();

WebSocket webSocket = okHttpClient.newWebSocket(request, new WebSocketListener() {...}

@DavidPerezIngeniero
Copy link

DavidPerezIngeniero commented Mar 7, 2018

Is the last solution good?
Why is this issue closed, if it looks like unsolved?.
I was working before with HttpUrlConnection and never experienced this problem. Server hasn't changed. So, probably the problem is with OkHttp.
Working with Android 4.4.

Server is Jetty based with Java 8.

@deberle
Copy link

deberle commented Mar 9, 2018

I am having this problem too.
It started to occur since we switched our server to an S3 instance.

@rhonyabdullah
Copy link

Hello, i'm facing this issue, reading this stackoverflow question says that this error is causing from the server. Any solution ?

@GeoffLedak
Copy link

I encountered this issue as well and was able to resolve it.

I was working with some existing code which used Retrofit. We have 3 different dev environments, the same endpoint was working fine in 2 of the environments, but I was getting this exception when using the third.

All 3 servers were returning the exact same 200 response.

The code I was working with was passing a boolean value of false as an empty @Body in a PUT call.

I changed this to an empty String instead and now it works fine, though I don't entirely understand why. Something somewhere must be looking for the null terminator character that an empty String provides.

@hlogmans
Copy link

hlogmans commented May 3, 2018

For posterity: I ran into this error frequently when using the Square bindings for Xamarin, using an NetworkInterceptor. This crash is thrown frequently (as described before) but should be handled by the retry on connection code. But somehow in Xamarin it crashes in such a way the retry is never done, and the exception is propagated to the app.

See mattleibow/square-bindings#20

@orende
Copy link

orende commented May 21, 2018

I ran into this problem recently when I was sending requests to a web server that was still in the process of starting up (it was being started by a docker container), which seemed to cause the server to send empty headers back to the client. The solution in that case was to wait for the server to be completely up before sending requests.

@rasik1010
Copy link

rasik1010 commented Jun 28, 2018

i have same issue and i find some solution:
the problem is HttpLoggingInterceptor , when we use HttpLoggingInterceptor that time the error java.io.EOFException: \n not found: limit=1 content=0d… comes

and when i use bellow code that time error not cumming, but if we dont use HttpLoggingInterceptor then we can not see API call logs in android studio logcat :(

`public static Retrofit getRestAdapter() {
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.addInterceptor(new Interceptor() {
        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request request = chain.request().newBuilder().addHeader("Connection", "close").build();
            return chain.proceed(request);

        }
    });

    return new Retrofit.Builder()
            .baseUrl(Configuration.getBaseUrl())
            .client(httpClient.build())
            .addConverterFactory(GsonConverterFactory.create())
            .build();

}`

i think if we can set Headers in HttpLoggingInterceptor then error can be solve but i didnt found any ways to set headers in HttpLoggingInterceptor object :(

anybody can help in this case please reply here ... thanks

@rhonyabdullah
Copy link

Good news,
This issue resolved just by adding Connection header as @rasik1010 say but i'm still using HttpLoggingInterceptor and it's working fine.
addHeader("Connection", "close")

@rasik1010
Copy link

@rhonyabdullah where/how did you put addHeader("Connection", "close") in HttpLoggingInterceptor? can you share that code please?

@houdangui1985
Copy link

@rasik1010 you are right, only disable the HttpLoggingInterceptor works for me. I tried addHeader("Connection", "close") and disable the Accept-Encoding gzip by updating the Accept-Encoding to "identity" , they both don't work @rhonyabdullah

@rhonyabdullah
Copy link

Using okHttpVersion = "3.10.0"
I'm using kotlin, but it is still readable i think. I'm writing this answer without any IDE, i'm just using this comment box, sorry if any mistake:

internal fun OkHttpClient.Builder.defaultBuilder(isDebug: Boolean)
        : OkHttpClient.Builder {
    if (isDebug) {
        addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
    }
    connectTimeout(ApiConstant.TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
    readTimeout(ApiConstant.TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
    writeTimeout(ApiConstant.TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
    return this
}

private fun getRequestHeader(chain: Interceptor.Chain): Request {
   return chain.request().newBuilder()
              .addHeader("Connection", "close")
              ..(my another header params)
              .build()
}

val clientBuilder: OkHttpClient.Builder = OkHttpClient.Builder().defaultBuilder(isDebug)
clientBuilder.addInterceptor { chain -> chain.proceed(getRequestHeader(chain)) }

return Retrofit.Builder()
                .baseUrl(myBaseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .client(clientBuilder.build())
                .build()

@rasik1010
Copy link

rasik1010 commented Jul 12, 2018

hi guys, recently we changed our server and now i am using bellow using HttpLoggingInterceptor and the error java.io.EOFException: \n not found: limit=1 content=0d… gone!!!!!

Now the issue is fixed, error was from server side, changed hosting server and issue was fixed automatically. earlier i was hosting on TSOHost where this issue was arraving
so i think this error its because of server

    public static Retrofit getRestAdapter() {

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.addInterceptor(interceptor);
       
        return new Retrofit.Builder()
                .baseUrl(Configuration.getBaseUrl())
                .client(httpClient.build())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

@wonmo01
Copy link

wonmo01 commented Sep 15, 2018

I faced the same issue Caused by: java.io.EOFException: \n not found: limit=0 content=….

The issue was when requests were made in conjunction with
Connection: keep-alive
Transfer-Encoding: chunked
with a long JSON response in the body, but the body was not written according to Chucked Transfer Encoding spec. https://en.wikipedia.org/wiki/Chunked_transfer_encoding

Like the suggestions above, adding Connection: close resolved the issue since it triggered to use UnknownLengthSource instead of ChunkedSource.

Alternative workaround is reading byte[] from ResponseBody.byteStream(), however this would mean the server response is not following Http1.1 spec where it sends Transfer-Encoding: chunked but the body format is not inserting

<< Size of chunk >>\r\n
<< Chunk body >>\r\n
...
repeat as many times
...
0\r\n
\r\n

OR,

the response header can specify Content-Length header.

@ghost
Copy link

ghost commented Jun 18, 2019

I faced the same error / stacktrace but with another cause; therefore the described workarounds did not work for me.

My problem was the authentication at the server: In my application, I get URLs in the form http://user:[email protected]. The user information are extracted and sent to the server in the Authorization header. But the credentials have not been removed from the URL, so I the requests contained the credentials both in the headers and in the URL. This caused a server (Spring Boot application) to misbehave, causing the error described in this issue.

Removing the credentials from the URL solved the problem for me

@malwinder-s
Copy link

          .addHeader("Connection", "close")

Didn't worked.

@kwek20
Copy link

kwek20 commented Dec 2, 2019

For me this happened when i connected to a server with HTTP, but it actually should have used HTTPS, check your URL!

@OhhhThatVarun
Copy link

@dotgc I have the exact use case. Could you let me know what you did to fix the error in your Android app? I'm also seeing them in our logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests