OkHttp3 - IOException: unexpected end of stream on okhttp3.Address@9d7c59b5
See original GitHub issueThe error occurs when OkHttp try to reuse a connection that is in FIN_WAIT2 state in server, because the server keep_alive timeout is lesser than the client timeout.
StackTrace:
Exception in thread "main" java.io.IOException: unexpected end of stream on okhttp3.Address@e06a4fc7
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:201)
at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:53)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.execute(RealCall.java:60)
at br.com.edallagnol.test.App.main(App.java:54)
Caused by: java.io.EOFException: \n not found: size=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:215)
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
... 17 more
Steps to reproduce:
-Configure a Tomcat(7 or 8) Server with a keep_alive timeout of 60 seconds (default); -Create a OkHttpClient with retryOnConnectionFailure(false) and the default ConnectionPool (5 min timeout); -Do a GET request with client.newCall(request).execute(); -Wait more than 60 seconds (or monitor the connection state, until FIN_WAIT2 state); -Do a GET request with client.newCall(request).execute(), using the same client;
Sample code:
OkHttpClient client = new OkHttpClient.Builder()
.retryOnConnectionFailure(false)
.build();
for (int i=0; i != 10; i++) {
Response response = client.newCall(new Request.Builder()
.url("http://localhost:8080/")
.get()
.build()).execute();
try {
System.out.println(response.body().string());
} finally {
response.close();
}
Thread.sleep(61000);
}
*OkHttp version 3.4.1.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:28 (5 by maintainers)
Top Results From Across the Web
Android OkHttp HTTP FAILED: java.io.IOException
I/okhttp.OkHttpClient: <-- HTTP FAILED: java.io.IOException: unexpected end of stream on http://10.0.2.2:30000/... java.io.
Read more >unexpected end of stream on com.android.okhttp.Address ...
Hi,. Why do I keep getting below error when trying to use simple PostAsync()? For example, below code is used to update the...
Read more >unexpected end of stream on okhttp3.Address@2c98c95e - B4X
Hi all, today I'm encountering this error message while connecting to my VPS where a B4J module is listening in order to serve...
Read more >IDEA-289610 - YouTrack
Can't connect to docker via ssh, getting: java.io.IOException: unexpected end of stream on http://127.0.0.1/... · As per machine to which I ssh: Client:...
Read more >IOException unexpected end of stream when listing locations ...
It appears that okhttp3 is falling over on itself inside the API. If I resend the request it tends to then go through...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s your fix:
response header (“Connection”:“close”) solved this issue in my case