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

ApolloParseException caused by SocketTimeoutError while reading response body #2783

Closed
tmtrademarked opened this issue Nov 30, 2020 · 5 comments

Comments

@tmtrademarked
Copy link
Contributor

Summary
Apollo throws ApolloParseException when reading the response times out.

Version
2.4.5

Description
This one seems odd. It's possible this is intended behavior somehow, but it felt strange enough that I decided to report it. We're seeing some crashes in our app in the ApolloParseInterceptor which appear to occur when it is unable to read the data from the OkHttp response without timing out. Here's the relevant exception:

okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException (Http2Stream.java:677)
okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut (Http2Stream.java:686)
okhttp3.internal.http2.Http2Stream$FramingSource.read (Http2Stream.java:382)
okhttp3.internal.connection.Exchange$ResponseBodySource.read (Exchange.java:276)
okio.internal.RealBufferedSourceKt.commonRead (RealBufferedSourceKt.java:39)
okio.RealBufferedSource.read (RealBufferedSource.java:189)
okio.internal.RealBufferedSourceKt.commonExhausted (RealBufferedSourceKt.java:49)
okio.RealBufferedSource.exhausted (RealBufferedSource.java:197)
okio.InflaterSource.refill (InflaterSource.java:112)
okio.InflaterSource.readOrInflate (InflaterSource.java:76)
okio.InflaterSource.read (InflaterSource.java:49)
okio.GzipSource.read (GzipSource.java:69)
okio.internal.RealBufferedSourceKt.commonRequest (RealBufferedSourceKt.java:60)
okio.RealBufferedSource.request (RealBufferedSource.java:206)
com.apollographql.apollo.api.internal.json.BufferedSourceJsonReader.nextNonWhitespace (BufferedSourceJsonReader.java:771)
com.apollographql.apollo.api.internal.json.BufferedSourceJsonReader.doPeek (BufferedSourceJsonReader.java:231)
com.apollographql.apollo.api.internal.json.BufferedSourceJsonReader.beginObject (BufferedSourceJsonReader.java:88)
com.apollographql.apollo.response.OperationResponseParser.parse (OperationResponseParser.java:82)
com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor.parse (ApolloParseInterceptor.java:87)
com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor$1.onResponse (ApolloParseInterceptor.java:53)
com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$executeHttpCall$1.onResponse (ApolloServerInterceptor.java:109)

It seems like maybe, somehow, the response it is receiving is not a JSON object? Would that cause a socket timeout, or am I misunderstanding this? I would only expect to see a Parse exception on some sort of malformed response, but the fact that the underlying issue here appears to have a SocketTimeout underneath feels odd to me. I'm going to add some additional handling to my application to see if I can get a better understanding of what's going wrong, but...

@martinbonnin
Copy link
Contributor

Hi 👋 ThatSocketTimeoutException seems appropriate. It looks like the server replied with HTTP 200 and response headers but OkHttp times out while reading the body. The OkHttp Response body is streamed so that callers don't have to keep everything in memory if they don't need to. So a timeout could happen at any time while reading the body.

@tmtrademarked
Copy link
Contributor Author

Hmm - so if I'm understanding you correctly, it seems like this is timing out while talking to our backend? In that case, wouldn't it be more appropriate to raise an ApolloNetworkException so clients can handle this like any other timeout case?

@martinbonnin
Copy link
Contributor

it seems like this is timing out while talking to our backend?

Yup

In that case, wouldn't it be more appropriate to raise an ApolloNetworkException so clients can handle this like any other timeout case?

Yup too, that makes perfect sense. The whole parse() call was wrapped into something that rethrows ApolloParseException but ApolloNetworkException would be more representative of the reality there.

@martinbonnin
Copy link
Contributor

I'll close this for now. 4.x has:

  • ApolloNetworkException for IO errors.
  • JsonEncodingException for bad JSON encoding.
  • JsonDataException for bad JSON data (bad types).

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants