-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Comments
@swankjesse mentioned the following
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. |
@simtse what device are you using? |
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. |
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?( |
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. |
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, |
Same issue here, OkHttpClient client = new OkHttpClient(); It never happens with okhttp include in Lollipop. |
Running into this issue? Please send me a test case! |
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.EOFException: \n not found: size=0 content=... I cannot image any reason that would cause the client spend more than 10s to read the response. Any idea? |
@dmoneyUK could you isolate this into a test case? There's lots of examples in |
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? |
@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. |
@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. |
@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. |
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:
Can you tell me why the GET request does not need to check connection readable? |
@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!) |
Still present in version 2.5.0 ... with connection.setRequestProperty("Connection", "close"); there is no more errors, but it's not a valid solution ... |
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 |
If you called Java's sockets have per design no way of knowing TCP connections are in state 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. |
@swankjesse Do you think adding isReadable() check for GET request while retryOnConnectionFailure is set to false is good idea? |
Im getting this on ~1/6 calls using POST
If I do the post via curl all is fine...this on okhttp 2.6.0 on android 6.0 |
The same error here.
On okhttp 2.6.0 and android 6.0 |
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:
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. |
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. |
@crossle did you fix the issue? |
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 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. |
Hi, anyone have solution for this problem? |
How to resolve the issue?
Code:
|
Is the last solution good? Server is Jetty based with Java 8. |
I am having this problem too. |
Hello, i'm facing this issue, reading this stackoverflow question says that this error is causing from the server. Any solution ? |
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. |
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. |
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. |
i have same issue and i find some solution: 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() {
}` 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 |
Good news, |
@rhonyabdullah where/how did you put addHeader("Connection", "close") in HttpLoggingInterceptor? can you share that code please? |
@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 |
Using
|
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
|
I faced the same issue The issue was when requests were made in conjunction with Like the suggestions above, adding Alternative workaround is reading
OR, the response header can specify |
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 Removing the credentials from the URL solved the problem for me |
Didn't worked. |
For me this happened when i connected to a server with HTTP, but it actually should have used HTTPS, check your URL! |
@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. |
We're getting an EOF exception with size=0 in the stream.
(Forked from issue 1114.)
The text was updated successfully, but these errors were encountered: