Closed milindsingh closed 2 years ago
The stacktrace tells that there had been some connection level issue. Once a SocketTimout and once a ProtocolException. This is an error which is not recoverable by the SDK itself.
How can we add a retry for this case?
Would be possible creating a middleware as like as the RetryMiddleware.
But you should be aware depending on the type of request a retry may not be possible as it could already have been reached the API.
With version 8.2.0 the RetryMiddleware can be configured to also retry on specific throwable classes as well as add any valid failsafe predicate
Describe the bug API calls fails with
java.util.concurrent.CompletionException
To Reproduce SDK v7.6 OK HTTP Client 3
Expected behavior No exception or failure.
Screenshots/Code snippet
Case 1:
stack_trace: "java.util.concurrent.CompletionException: java.net.SocketTimeoutException: timeout at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source) at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) at com.commercetools.http.okhttp3.CtOkHttp3Client$OkHttpResponseFuture.onFailure(CtOkHttp3Client.java:145) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:180) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused by: java.net.SocketTimeoutException: timeout at okio.Okio$4.newTimeoutException(Okio.java:232) at okio.AsyncTimeout.exit(AsyncTimeout.java:286) at okio.AsyncTimeout$2.read(AsyncTimeout.java:241) at okio.RealBufferedSource.indexOf(RealBufferedSource.java:358) at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:230) at okhttp3.internal.http1.Http1ExchangeCodec.readHeaderLine(Http1ExchangeCodec.java:242) at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.java:213) at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.java:115) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:94) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:43) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at com.commercetools.http.okhttp3.CtOkHttp3Client$UnzippingInterceptor.intercept(CtOkHttp3Client.java:165) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at io.opentelemetry.javaagent.shaded.instrumentation.okhttp.v3_0.TracingInterceptor.intercept(TracingInterceptor.java:44) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172) ... 4 common frames omitted Caused by: javax.net.ssl.SSLException: Socket closed at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source) at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source) at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source) at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl.handleException(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(Unknown Source) at okio.Okio$2.read(Okio.java:140) at okio.AsyncTimeout$2.read(AsyncTimeout.java:237) ... 30 common frames omitted Caused by: java.net.SocketException: Socket closed at java.base/java.net.SocketInputStream.read(Unknown Source) at java.base/java.net.SocketInputStream.read(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(Unknown Source) ... 33 common frames omitted "
Case 2:
stack_trace: "java.util.concurrent.CompletionException: java.net.ProtocolException: unexpected end of stream at io.vrap.rmf.base.client.utils.Utils.lambda$wrapToCompletionException$0(Utils.java:20) at java.base/java.util.Optional.map(Unknown Source) at com.commercetools.http.okhttp3.CtOkHttp3Client.toResponse(CtOkHttp3Client.java:92) at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.complete(Unknown Source) at com.commercetools.http.okhttp3.CtOkHttp3Client$OkHttpResponseFuture.onResponse(CtOkHttp3Client.java:150) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused by: java.net.ProtocolException: unexpected end of stream at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.read(Http1ExchangeCodec.java:478) at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286) at okio.RealBufferedSource.read(RealBufferedSource.java:51) at okio.RealBufferedSource.exhausted(RealBufferedSource.java:61) at okio.InflaterSource.refill(InflaterSource.java:102) at okio.InflaterSource.read(InflaterSource.java:62) at okio.GzipSource.read(GzipSource.java:80) at okio.Buffer.writeAll(Buffer.java:1143) at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:111) at okhttp3.ResponseBody.bytes(ResponseBody.java:136) at io.vrap.rmf.base.client.utils.Utils.lambda$wrapToCompletionException$0(Utils.java:17) ... 11 common frames omitted ",
Stack information (please complete the following information):
Additional context Its happens only 2-3 time in a day.