question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Proxy connection always fail with unexpected end of stream.

See original GitHub issue

Hi,

On some proxies (squid proxy) OKHttpClient works well. On others (also squid proxies), for an unknown reason, I always get the "unexpected end of stream" error (Caused by: java.io.EOFException: \n not found: size=0 content). For all the browsers and other http clients (java, apache, jetty), the proxy works.

Exception in thread "main" java.io.IOException: unexpected end of stream at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:215) at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127) at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:732) at okhttp3.internal.http.HttpEngine.access$2(HttpEngine.java:726) at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:714) at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:566) at okhttp3.RealCall.getResponse(RealCall.java:245) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:200) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:162) at okhttp3.RealCall.execute(RealCall.java:59) at testok.run(testok.java:54) at testok.main(testok.java:61) Caused by: java.io.EOFException: \n not found: size=0 content=... at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196) at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:191) ... 11 more

I have tried to debug it using the OKHttp and okio sources, by sniffing with Wireshark, but no luck. Somehow the server response is missing. How can I debug this?

The code that I use is quite simple.

` Authenticator proxyAuthenticator = new Authenticator() { public Request authenticate(Route route, Response response) throws IOException { String credential = Credentials.basic(user, password); return response.request().newBuilder() .header(“Proxy-Authorization”, credential) .build(); } };

OkHttpClient client = new OkHttpClient.Builder()
    .protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1, Protocol.SPDY_3))
    .connectTimeout(60, TimeUnit.SECONDS)
    .writeTimeout(60, TimeUnit.SECONDS)
    .readTimeout(60, TimeUnit.SECONDS)
    .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, port)))
    .proxyAuthenticator(proxyAuthenticator)
    .authenticator(proxyAuthenticator)
    .build();

Request request = new Request.Builder()
    .url(url)
    .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0")
    .build();

Response response = client.newCall(request).execute();
System.out.println("response " + response.code());
return response.body().string();`

Best Regards, Stefan Matei

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
DmitriyYakovlevcommented, Jan 31, 2018

Hi. Is there any solution for described problem in any version? I have the same problem

0reactions
swankjessecommented, Apr 13, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - okHttpClient proxy connection gives unexpected end of ...
Below is the code that I am trying but it gives unexpected end of stream exception.
Read more >
4.7. The Mysteries of Connection Close - HTTP - O'Reilly
Connections can close at any time, even in non-error conditions. HTTP applications have to be ready to properly handle unexpected closes.
Read more >
502 Bad Gateway Unexpected EOF | Apigee Edge
One of the typical causes for 502 Bad Gateway Error is the Unexpected EOF error ... Target server is not properly configured to...
Read more >
java.i.o.EOFException:unexpected end of ZLIB input stream
This problem sometimes occurs when the amout of data transferred between the client and the server is huge. One of the simplest ways...
Read more >
IOS simulator error unexpected end of stream on Connection ...
IOS simulator error unexpected end of stream on Connection{127.0.0.1:53492, proxy=DIRECT hostAddress=/127.0.0.1:53492 cipherSuite=none protocol= ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found