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.

okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR/ CANCEL

See original GitHub issue

I am connecting to web service with last version retrofit but get me bellow error :

okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR

My code is like bellow :

try {
                    // Create a trust manager that does not validate certificate chains
                    final TrustManager[] trustAllCerts = new TrustManager[]{
                            new X509TrustManager() {
                                @Override
                                public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                                }

                                @Override
                                public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                                }

                                @Override
                                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                    return new java.security.cert.X509Certificate[]{};
                                }
                            }
                    };

                    // Install the all-trusting trust manager
                    final SSLContext sslContext = SSLContext.getInstance("SSL");
                    sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
                    // Create an ssl socket factory with our all-trusting manager
                    final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                    OkHttpClient.Builder builder = new OkHttpClient.Builder();
                    builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
                    builder.hostnameVerifier(new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    });

                    OkHttpClient okHttpClient = builder.
                            build();
                    Retrofit retrofit = new Retrofit.Builder()
                            .baseUrl("https://xxx")
                            .client(okHttpClient)
                            .addConverterFactory(GsonConverterFactory.create())
                            .addConverterFactory(ScalarsConverterFactory.create())
                            .build();
                    final PublicApi request = retrofit.create(PublicApi.class);
                    Call<GetStatusSaveContactListModel> call = request.sendContactLists("saveContactList", obj.toString());
                    call.enqueue(new Callback<GetStatusSaveContactListModel>() {
                        @Override
                        public void onResponse(@NonNull Call<GetStatusSaveContactListModel> call, @NonNull Response<GetStatusSaveContactListModel> response) {
                        }

                        @Override
                        public void onFailure(@NonNull Call<GetStatusSaveContactListModel> call, Throwable t) {
                        }
                    });

                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

And

@POST("/web_service/mobile/rest")
Call<GetStatusSaveContactListModel> sendContactLists(@Query("function") String function,
                                                     @Query("data") String data);

And

implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:44 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Rafhackcommented, Dec 21, 2020

This is happening to me in production, but I am not able to reproduce the problem when debugging

Non-fatal Exception: okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL
       at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:158)
       at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:131)
       at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
       at okhttp3.RealCall.execute(RealCall.java:92)
       at com.google.firebase.perf.network.FirebasePerfOkHttpClient.execute(FirebasePerfOkHttpClient.java:43)
       at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
       at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:45)
       at io.reactivex.Observable.subscribe(Observable.java:12090)
       at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
       at io.reactivex.Observable.subscribe(Observable.java:12090)
       at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
       at io.reactivex.Single.subscribe(Single.java:3438)
       at io.reactivex.internal.operators.single.SingleToObservable.subscribeActual(SingleToObservable.java:35)
       at io.reactivex.Observable.subscribe(Observable.java:12090)
       at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
       at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
       at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
       at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)
3reactions
balsikandar-okcreditcommented, Feb 25, 2020

Have we got any update on this? I get this when i trigger a specific api in quick succession for example: API called API called again (before i could get response) throws StreamResetException

but if i call the API wait for some time i get the response API called . . . waiting . . after some waiting finally i get the response

Read more comments on GitHub >

github_iconTop Results From Across the Web

okhttp3.internal.http2.StreamResetException: stream was ...
StreamResetException : stream was reset: CANCEL at okhttp3.internal.http2.Http2Stream$FramingSource.checkNotClosed(Http2Stream.java:436) at ...
Read more >
What causes "java.io.IOException: stream was reset: CANCEL ...
I'm experimenting with OKHttp (version 2.0.0-RC2) and SPDY and seeing IOException: stream was reset: CANCEL quite a lot, maybe 10% or more ...
Read more >
okhttp3.internal.http2.StreamResetException: stream was reset
internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR. Hi everyone,. When i use okhttp3 to send event about 10 times (like ask ...
Read more >
Stream Was Reset: Protocol_Error, While Using Retrofit In 3G ...
Indicates that the contacted node reported a protocol error. ... StreamResetException: stream was reset: CANCEL at okhttp3.internal.http2. in case the ...
Read more >
Mobile Androind app: 'stream was reset: PROTOCOL_ERROR ...
IOException: stream was reset: PROTOCOL_ERROR at com.squareup.okhttp.internal.spdy.SpdyStream.getResponseHeaders(SpdyStream.java:145)
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