Okhttp: java.io.EOFException: \n not found: limit=0 content=…

Created on 23 Aug 2019  Â·  3Comments  Â·  Source: square/okhttp

    api 'com.squareup.okhttp3:okhttp:4.1.0'

Occur sometimes.

W/System.err: java.io.IOException: unexpected end of stream on http://172.16.10.21:8880/...
        at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:205)
        at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:105)
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:82)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:37)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.kt:184)
        at okhttp3.RealCall.execute(RealCall.kt:66)
        at com.lcbtn.utils.HttpUtils.get(HttpUtils.java:125)
        at com.lcbtn.utils.HttpUtils$2.run(HttpUtils.java:84)
        at java.lang.Thread.run(Thread.java:818)
    Caused by: java.io.EOFException: \n not found: limit=0 content=…
W/System.err:     at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:231)
        at okhttp3.internal.http1.Http1ExchangeCodec.readHeaderLine(Http1ExchangeCodec.kt:210)
        at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:181)
        ... 19 more
$ curl http://172.16.10.21:8880/FSCPService/Program\?providerId\=cntv\&cityId\=7680\&programID\=CNTV2-1200064244\&cntv-version\=1006 -v 
*   Trying 172.16.10.21:8880...
* TCP_NODELAY set
* Connected to 172.16.10.21 (172.16.10.21) port 8880 (#0)
> GET /FSCPService/Program?providerId=cntv&cityId=7680&programID=CNTV2-1200064244&cntv-version=1006 HTTP/1.1
> Host: 172.16.10.21:8880
> User-Agent: curl/7.65.3
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Server: NGINX(CnPanel,LNMP)
< Date: Fri, 23 Aug 2019 02:59:34 GMT
< Content-Type: text/html
< Content-Length: 192
< Location: http://172.16.10.21:8880/FSCPService/Program/?providerId=cntv&cityId=7680&programID=CNTV2-1200064244&cntv-version=1006
< Connection: keep-alive
< 
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>NGINX(CnPanel,LNMP)</center>
</body>
</html>
* Connection #0 to host 172.16.10.21 left intact

bug needs info

Most helpful comment

I have the same issue when using Ktor (https://github.com/ktorio/ktor/issues/1708#issuecomment-609988128) but was able to trace it back to an issue with connection pooling when retryOnConnectionFailure is set to false, which is the default with Ktor.

The EOFException is likely thrown when a pooled connection was re-used but has timed-out on the server in the meantime.

I guess that is intended behavior? It's just that the exception is very confusing for developers.

All 3 comments

This occur sometimes, so my curl -v log may not cause the bug.....

private OkHttpClient client = new OkHttpClient.Builder()
        .connectTimeout(10, TimeUnit.SECONDS)
        .readTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(10, TimeUnit.SECONDS)
        .retryOnConnectionFailure(false)
        .build();

I use retryOnConnectionFailure(false) Because of this?

Can you provide a test server we can test against? This is likely a problem with the response from the server, possibly differs because of different headers or connection negotiation. Without that, we can't help.

I have the same issue when using Ktor (https://github.com/ktorio/ktor/issues/1708#issuecomment-609988128) but was able to trace it back to an issue with connection pooling when retryOnConnectionFailure is set to false, which is the default with Ktor.

The EOFException is likely thrown when a pooled connection was re-used but has timed-out on the server in the meantime.

I guess that is intended behavior? It's just that the exception is very confusing for developers.

Was this page helpful?
0 / 5 - 0 ratings