apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.74k stars 653 forks source link

Apollo Server throws fatal exceptions when it times out #1143

Closed bpollock-vida closed 5 years ago

bpollock-vida commented 5 years ago

I would expect these to come down through onError in Apollo-rx2.

Various connection timeouts and host issues can throw an exception when I’m executing Apollo queries/mutations with “Failed to execute http call”. Shouldn’t these come through as errors instead of exceptions?

Exception types:

Apollo Crashes:

       at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(SourceFile:704)
       at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(SourceFile:701)
       at io.reactivex.internal.observers.LambdaObserver.onError(SourceFile:77)
       at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onError(SourceFile:119)
       at io.reactivex.internal.observers.BasicFuseableObserver.onError(SourceFile:100)
       at io.reactivex.internal.observers.BasicFuseableObserver.onError(SourceFile:100)
       at io.reactivex.internal.operators.observable.ObservableZip$ZipCoordinator.checkTerminated(SourceFile:239)
       at io.reactivex.internal.operators.observable.ObservableZip$ZipCoordinator.drain(SourceFile:170)
       at io.reactivex.internal.operators.observable.ObservableZip$ZipObserver.onError(SourceFile:283)
       at io.reactivex.internal.observers.BasicFuseableObserver.onError(SourceFile:100)
       at io.reactivex.internal.observers.BasicFuseableObserver.onError(SourceFile:100)
       at io.reactivex.internal.observers.BasicFuseableObserver.onError(SourceFile:100)
       at io.reactivex.internal.observers.BasicFuseableObserver.onError(SourceFile:100)
       at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onError(SourceFile:119)
       at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.tryOnError(SourceFile:85)
       at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onError(SourceFile:73)
       at com.apollographql.apollo.rx2.Rx2Apollo$2$1.onFailure(SourceFile:95)
       at com.apollographql.apollo.ApolloCall$Callback.onResponse(SourceFile:115)
       at com.apollographql.apollo.internal.RealApolloCall$1.onFailure(SourceFile:238)
       at com.apollographql.apollo.internal.interceptor.ApolloCacheInterceptor$1$1.onFailure(SourceFile:91)
       at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor$1.onFailure(SourceFile:63)
       at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onFailure(SourceFile:89)
       at okhttp3.RealCall$AsyncCall.execute(SourceFile:148)
       at okhttp3.internal.NamedRunnable.run(SourceFile:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)```

Caused by com.a.a.c.d: Failed to execute http call at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onFailure(SourceFile:89) at okhttp3.RealCall$AsyncCall.execute(SourceFile:148) at okhttp3.internal.NamedRunnable.run(SourceFile:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)

bpollock-vida commented 5 years ago

at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(SourceFile:704)

I'm missing an onError I guess. This is my bad. These stack traces are hard to understand at times.

kris1837 commented 5 years ago

I have a similar problem with ApoloClient`

`/ W/System.err: com.apollographql.apollo.exception.ApolloNetworkException: Failed to execute http call
/ W/System.err:     at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onFailure(ApolloServerInterceptor.java:91)
/ W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:161)
/ W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
/ W/System.err:     at java.lang.Thread.run(Thread.java:764)
/ W/System.err: Caused by: java.net.SocketTimeoutException: timeout
/ W/System.err:     at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.java:616)
/ W/System.err:     at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:624)
/ W/System.err:     at okhttp3.internal.http2.Http2Stream.takeResponseHeaders(Http2Stream.java:146)
/ W/System.err:     at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:127)
/ W/System.err:     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at kirill.carca.com.webtotem.repository.AppoloClientWrapper$getClient$1.intercept(AppoloClientWrapper.kt:34)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
/ W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
/ W/System.err:     ... 4 more
/ W/System.err: com.apollographql.apollo.exception.ApolloNetworkException: Failed to execute http call
/ W/System.err:     at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onFailure(ApolloServerInterceptor.java:91)
/ W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:161)
/ W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
/ W/System.err:     at java.lang.Thread.run(Thread.java:764)
/ W/System.err: Caused by: java.net.SocketTimeoutException: timeout
/ W/System.err:     at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.java:616)
/ W/System.err:     at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:624)
/ W/System.err:     at okhttp3.internal.http2.Http2Stream.takeResponseHeaders(Http2Stream.java:146)
/ W/System.err:     at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:127)
/ W/System.err:     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at kirill.carca.com.webtotem.repository.AppoloClientWrapper$getClient$1.intercept(AppoloClientWrapper.kt:34)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
/ W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
/ W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
/ W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
/ W/System.err:     ... 4 more`
`val clientBuilder = OkHttpClient.Builder()
        val loggingInterceptor = HttpLoggingInterceptor()
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
        clientBuilder.addInterceptor(loggingInterceptor)

        // increase timeout for slow services
        clientBuilder
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)

        clientBuilder.addInterceptor { chain ->
            val request = chain.request().newBuilder().addHeader("Authorization",
                    "Bearer " + token!!).build()
            chain.proceed(request)
        }
        return ApolloClient.builder()
                .serverUrl(BASE_URL)
                .okHttpClient(clientBuilder.build())
                .clientBuilder.build()))
                .build()`
kris1837 commented 5 years ago

Have to remove

override fun onNetworkError(e: ApolloNetworkException) {
                    super.onNetworkError(e)
                }

In Callback

bpollock-vida commented 5 years ago

I closed this issue because it was programmer error (for me) you might want to file a new one.

Elangovanpdl commented 1 year ago

Have to remove

override fun onNetworkError(e: ApolloNetworkException) {
                    super.onNetworkError(e)
                }

In Callback

Is this solution working ? @kris1837 @bpollock-vida