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

java.io.EOFException at okio.RealBufferedSource.require(RealBufferedSource.java:60) when body is empty when 404 error status #3646

Closed
Etery13 opened this issue Oct 10, 2017 · 9 comments
Labels
needs info More information needed from reporter stackoverflow Referred to stackoverflow

Comments

@Etery13
Copy link

Etery13 commented Oct 10, 2017

Dear community!
Could you please help me with my bug?
There is response, request and an exception in logs below. I expect 404 code response but my tests failed because of weird exception.
I replaced url and token in logs with dummy values.
logs:

Oct 10, 2017 7:09:47 PM okhttp3.internal.platform.Platform log
INFO: --> GET https://tttp.com/rs/api/uw/uwUrl?adminSystemId=sdkhgskdjg&programId=12345
Oct 10, 2017 7:09:47 PM okhttp3.internal.platform.Platform log
INFO: Cookie: wdp-initial-auth=false; LtpaToken2=ttoken; Path=/; HttpOnly
Oct 10, 2017 7:09:47 PM okhttp3.internal.platform.Platform log
INFO: --> END GET
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: <-- 404 Not Found https://tttp.com/rs/api/uw/uwrUrl?adminSystemId=sdkhgskdjg&programId=12345 (393ms)
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: X-Backside-Transport: FAIL FAIL
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Connection: Keep-Alive
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Transfer-Encoding: chunked
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Cache-Control: no-store, no-cache, must-revalidate
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Content-Language: en-US
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Date: Tue, 10 Oct 2017 16:09:47 GMT
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Expires: Mon, 09 Oct 2017 16:09:48 GMT
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: Pragma: no-cache
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: X-Powered-By: Servlet/3.1
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: X-Vcap-Request-Id: ef703926-b9d0-4e30-78e2-861345450103
Oct 10, 2017 7:09:48 PM okhttp3.internal.platform.Platform log
INFO: X-Global-Transaction-ID: 0344791159dcf0cc375654d1

java.io.EOFException
at okio.RealBufferedSource.require(RealBufferedSource.java:60)
  at okio.GzipSource.consumeHeader(GzipSource.java:114)
  at okio.GzipSource.read(GzipSource.java:73)
  at okio.RealBufferedSource.request(RealBufferedSource.java:67)
  at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:240)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
  at okhttp3.RealCall.execute(RealCall.java:69)
  at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
@yschimke
Copy link
Collaborator

This isn't a reproducible bug or something that looks like it requires a fix in OkHttp (yet). Can you please post on stackoverflow with a reproducible test case, or at least your client code.

Please include in your stackoverflow post whether it fails the same way, with or without HttpLoggingInterceptor.

@yschimke yschimke added needs info More information needed from reporter stackoverflow Referred to stackoverflow labels Oct 11, 2017
@shuaimango
Copy link

我也老是出现这个异常 急求解决

@yschimke
Copy link
Collaborator

Google Translate: "I also always appear this exception urgently needed to solve"

@shuaimango can you link to your post on stackoverflow?

@skristof
Copy link

Hi,
This is a bug quite hard to reproduce. It happens when an empty Gzip stream is returned from the server side as response body and HTTPLoggingInterceptor is set to BODY level. It tries to log the body but the okio.GzipSource.consumeHeader requires a 10 bytes Gzip header. The check at okio.RealBufferedSource.require throws an EOFException.

The responseBody.contentLength is -1 in this case. Anyhow a -1 contentLength should not be logged, so I suggest to insert another check at HTTPLoggingInterceptor line 238
else if (responseBody.contentLength() <= 0) { logger.log("<-- END HTTP (content length <= 0)"); }

Workaround is not to log the Response BODY.
(Real life example: Microsoft PowerBI API returnes a 200 OK response with a 0 byte gzip body rather than an empty json.)

@swankjesse
Copy link
Member

Can you report the bug to the maintainers of the Microsoft PowerBI API? Their API is wrong.

@skristof
Copy link

skristof commented Nov 25, 2018

@swankjesse I'm not sure about it. It's a response to a POST request.

The method hasBody(Response response) in okhttp3.internal.http.HttpHeaders returns true if the response code is 200. In case of a 200 response with empty body (Content-Length: 0) shouldn't it return false?

Full header:
access-control-allow-credentials →true
access-control-allow-origin →chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
cache-control →no-store, must-revalidate, no-cache
content-encoding →gzip
content-length →0
content-type →application/octet-stream
date →Sun, 25 Nov 2018 13:40:47 GMT
requestid →709adf93-2f60-4a7e-9fdb-dfbdc5457195
server →Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0
status →200
strict-transport-security →max-age=31536000; includeSubDomains
x-content-type-options →nosniff
x-frame-options →deny

@swankjesse
Copy link
Member

The content-encoding is not Gzip because it doesn’t have the required 10-byte Gzip header.

@kngmat004
Copy link

Getting the same issue on a 202 No Content with a zero length response body

@yschimke
Copy link
Collaborator

@kngmat004 you should report the problem to whoever hosts the server. If it's the same as above it's a bug.

If you really need to handle it in the client, because the server can't be fixed, consider using a network interceptor to change headers to work around it.

If you think it's a bug in OkHttp please provide a reproducible example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info More information needed from reporter stackoverflow Referred to stackoverflow
Projects
None yet
Development

No branches or pull requests

7 participants
@swankjesse @yschimke @Etery13 @skristof @shuaimango @kngmat004 and others