okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

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

Open sealiasheq opened this issue 7 years ago • 60 comments

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'

sealiasheq avatar Apr 04 '18 12:04 sealiasheq

yes, I am facing same issues, is there any solution yet?

osama415 avatar Apr 04 '18 17:04 osama415

i am also facing this issue Exception occurs at okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR at okhttp3.internal.http2.Http2Stream$FramingSource.checkNotClosed(Http2Stream.java:436) at okhttp3.internal.http2.Http2Stream$FramingSource.read(Http2Stream.java:338) at okio.ForwardingSource.read(ForwardingSource.java:35) at okio.RealBufferedSource.read(RealBufferedSource.java:46) at okhttp3.internal.cache.CacheInterceptor$1.read(CacheInterceptor.java:174) at okio.RealBufferedSource$1.read(RealBufferedSource.java:430) at java.io.InputStream.read(InputStream.java:101)

owen5586331 avatar Jun 26 '18 01:06 owen5586331

This isn’t actionable as-is. Could you provide the server URL that triggers this? Or a test case that reproduces?

swankjesse avatar Jul 05 '18 01:07 swankjesse

We are seeing the same issue with (openjdk version "11" 2018-09-25) and it is related to #3146, i.e. something with http/2.

We tried versions from 3.11.0 down to 3.3.0 and only 3.2.0 works for us. The strange thing is that sometimes we get this PROTOCOL_ERROR, but sometimes also http2.ConnectionShutdownException: null:

Caused by: okhttp3.internal.http2.ConnectionShutdownException: null
        at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:247)
        at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:230)
        at okhttp3.internal.http2.Http2Codec.writeRequestHeaders(Http2Codec.java:113)
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:50)
        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:200)
        at okhttp3.RealCall.execute(RealCall.java:77)

And sometimes stream cancel:

Caused by: okhttp3.internal.framed.StreamResetException: stream was reset: CANCEL
        at okhttp3.internal.framed.FramedStream.getResponseHeaders(FramedStream.java:145)
        at okhttp3.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:149)
        at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:775)
        at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:86)
        at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:760)
        at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:613)
        at okhttp3.RealCall.getResponse(RealCall.java:244)
        at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
        at okhttp3.RealCall.execute(RealCall.java:57)

Also this is a rather rare issue but for certain requests reproducable. We'll try to produce a failing test for the latest 3.11.0

karussell avatar Nov 09 '18 11:11 karussell

I have the same problem with okhttp3.12 + retrofit 2 The server is in golang 1.11.5 (gorilla/mux and I try also chi) My use case is to enqueue about 100 query, I have about 20% of the query which have a protocol_error

okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR 2019-02-03 23:52:09.691c W/System.err: at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:158) 2019-02-03 23:52:09.691c W/System.err: at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:131) 2019-02-03 23:52:09.691c W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88) 2019-02-03 23:52:09.691c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-02-03 23:52:09.692c W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) 2019-02-03 23:52:09.692c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-02-03 23:52:09.692c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-02-03 23:52:09.693c W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 2019-02-03 23:52:09.693c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-02-03 23:52:09.693c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-02-03 23:52:09.693c W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 2019-02-03 23:52:09.693c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-02-03 23:52:09.694c W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) 2019-02-03 23:52:09.694c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-02-03 23:52:09.694c W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-02-03 23:52:09.695c W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254) 2019-02-03 23:52:09.696c W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200) 2019-02-03 23:52:09.696c W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 2019-02-03 23:52:09.696c W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 2019-02-03 23:52:09.696c W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 2019-02-03 23:52:09.696c W/System.err: at java.lang.Thread.run(Thread.java:764)

psohm avatar Feb 03 '19 23:02 psohm

Can you enable HTTP/2 frame logging and try again?

  private static void enableHttp2FrameLogging() {
    frameLogger = Logger.getLogger(Http2.class.getName());
    frameLogger.setLevel(Level.FINE);
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINE);
    handler.setFormatter(new SimpleFormatter() {
      @Override public String format(LogRecord record) {
        return Util.format("%s%n", record.getMessage());
      }
    });
    frameLogger.addHandler(handler);
  }
}

swankjesse avatar Feb 03 '19 23:02 swankjesse

tks for your very quick answer you can find the full log on https://pastebin.com/5rj2kQHL I hope you will find what is wrong I can also provide the go server and the java code if needed

My query is a POST always on the same URL it contains a JSON Body and there is an authorization bearer in the header

I also tryied to remove the header (the autorisation bearer), it doesn't work also.

psohm avatar Feb 04 '19 07:02 psohm

Yep, that'd be handy. As small as you can make it please.

swankjesse avatar Feb 04 '19 12:02 swankjesse

I set up for you a server with the golang server the endpoint is https://myvoip.w3france.com:10443/item/2 in POST For reasons I can't explain, there are less protocol problem with the server (about 3/4%) vs my dev machine on the same wifi network (in that case I use 4G) And last information, I have a OnePlus 5T with Android 9. Didn't try it from other device.

Retrofit.Builder builder =
                new Retrofit.Builder()
                        .baseUrl("https://myvoip.w3france.com:10443/")
                        .addConverterFactory(GsonConverterFactory.create());

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1));
        Retrofit retrofit = builder.client(httpClient.build()).build();

        AuthService service = retrofit.create(AuthService.class);

        // iterate over each item of the nomtable
        for (int i = 0; i < 500; i++) {
                final String id = Integer.toString(i);

                RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), "");

                Call<String> call = service.sendItem(id, body);

                call.enqueue(new Callback<String>() {
                    @Override
                    public void onResponse(Call<String> call, Response<String> response) {
                        Log.d(TAG, "Success " + id);

                    }

                    @Override
                    public void onFailure(Call<String> call, Throwable t) {
                        Log.d(TAG, "Failure " + id);
                        Log.d(TAG, t.getMessage());
                        t.printStackTrace();
                    }
                });
        }

and AuthService.java

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Path;

public interface AuthService {
    @POST("item/{item}")
    Call<String> sendItem(
            @Path("item") String itemGuid,
            @Body RequestBody body);
}

psohm avatar Feb 04 '19 13:02 psohm

Having the same issue; it happens always when there is bad connection (e.g. using 2G with bad signal). Trying to retrieve a JSON of ~80kB on 2G. I am using retrofit:2.5.0.

2019-02-28 14:14:34.304 22789-22789/? W/System.err: okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR
2019-02-28 14:14:34.305 22789-22789/? W/System.err:     at okhttp3.internal.http2.Http2Stream$FramingSource.read(Http2Stream.java:420)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okhttp3.internal.http2.Http2Codec$StreamFinishingSource.read(Http2Codec.java:205)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.RealBufferedSource.read(RealBufferedSource.java:47)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.RealBufferedSource.exhausted(RealBufferedSource.java:57)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.InflaterSource.refill(InflaterSource.java:102)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.InflaterSource.read(InflaterSource.java:62)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.GzipSource.read(GzipSource.java:80)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.RealBufferedSource.read(RealBufferedSource.java:47)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.ForwardingSource.read(ForwardingSource.java:35)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at retrofit2.OkHttpCall$ExceptionCatchingResponseBody$1.read(OkHttpCall.java:296)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okio.RealBufferedSource$1.read(RealBufferedSource.java:439)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:288)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:351)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:180)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at java.io.InputStreamReader.read(InputStreamReader.java:184)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at okhttp3.ResponseBody$BomAwareReader.read(ResponseBody.java:259)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1295)
2019-02-28 14:14:34.307 22789-22789/? W/System.err:     at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1030)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.stream.JsonReader.nextString(JsonReader.java:815)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:402)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:390)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
2019-02-28 14:14:34.308 22789-22789/? W/System.err:     at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
2019-02-28 14:14:34.309 22789-22789/? W/System.err:     at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
2019-02-28 14:14:34.309 22789-22789/? W/System.err:     at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
2019-02-28 14:14:34.309 22789-22789/? W/System.err:     at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
2019-02-28 14:14:34.309 22789-22789/? W/System.err:     at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223)
2019-02-28 14:14:34.309 22789-22789/? W/System.err:     at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
2019-02-28 14:14:34.310 22789-22789/? W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
2019-02-28 14:14:34.310 22789-22789/? W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
2019-02-28 14:14:34.310 22789-22789/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2019-02-28 14:14:34.311 22789-22789/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2019-02-28 14:14:34.311 22789-22789/? W/System.err:     at java.lang.Thread.run(Thread.java:764)

Issue is resolved by using HTTP 1.1 (not a good solution though):

        List<Protocol> protocols = new ArrayList<>();
        protocols.add(Protocol.HTTP_1_1);
        httpClient.protocols(protocols);

c0dehunter avatar Feb 28 '19 13:02 c0dehunter

Facing the same issue

Logs

2019-08-24 16:51:38.217 30729-30729/com.minimicro.sevenup W/System.err: okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL 2019-08-24 16:51:38.217 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http2.Http2Stream.takeResponseHeaders(Http2Stream.java:153) 2019-08-24 16:51:38.217 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:125) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-08-24 16:51:38.218 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 2019-08-24 16:51:38.219 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) 2019-08-24 16:51:38.220 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147) 2019-08-24 16:51:38.220 30729-30729/com.minimicro.sevenup W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 2019-08-24 16:51:38.220 30729-30729/com.minimicro.sevenup W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 2019-08-24 16:51:38.220 30729-30729/com.minimicro.sevenup W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 2019-08-24 16:51:38.220 30729-30729/com.minimicro.sevenup W/System.err: at java.lang.Thread.run(Thread.java:764)

Lib's implementation 'com.squareup.retrofit2:retrofit:2.4.0' implementation 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0' Call @Multipart @POST(EnumsClass.API_URL.addAudit) Call<First_Audits_Response> AddAuditsForTest( @Part MultipartBody.Part file, @Part MultipartBody.Part file2, @Part MultipartBody.Part file3, @Part MultipartBody.Part file4, @Part MultipartBody.Part file5, @Part MultipartBody.Part file6, @Part("AuditIdByDevice") RequestBody AuditIdByDevice, @Part("AuditBy") RequestBody AuditBy, );

BuilderClass

static Gson gson = new GsonBuilder() .setLenient() .serializeNulls() .create();

public static Retrofit getClient(String baseUrl, OkHttpClient.Builder okhhtpBuilder) {
    if (retrofit == null) {

        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(okhhtpBuilder.build())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
    }
    return retrofit;
}

aqibshxhzd avatar Aug 24 '19 11:08 aqibshxhzd

Any update on this? StackTrace:

Fatal Exception: okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR 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 ai.beans.driver.networking.NetworkInterceptor.intercept(NetworkInterceptor.kt:22) 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$AsyncCall.execute(RealCall.java:200) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 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:764)

badgroover avatar Oct 13 '19 17:10 badgroover

we are having the same issue.

sandys avatar Oct 30 '19 12:10 sandys

I'm also having the same issue and it is crashing the app. Caused by okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL at okhttp3.internal.http2.Http2Stream$FramingSource.read(Http2Stream.java:381) at okhttp3.internal.http2.Http2Codec$StreamFinishingSource.read(Http2Codec.java:213) at okio.RealBufferedSource.read(RealBufferedSource.kt:41) at okhttp3.internal.cache.CacheInterceptor$1.read(CacheInterceptor.java:174) at okio.RealBufferedSource.read(RealBufferedSource.kt:41) at okio.ForwardingSource.read(ForwardingSource.kt:29) at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:290) at okio.RealBufferedSource.request(RealBufferedSource.kt:62) at com.squareup.moshi.JsonUtf8Reader.nextNonWhitespace(JsonUtf8Reader.java:996) at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:309) at com.squareup.moshi.JsonUtf8Reader.peek(JsonUtf8Reader.java:193)

ten-skv avatar Nov 01 '19 14:11 ten-skv

faced this issue on Samsung SM-N960F (and 3 other models of Samsung, Android 8). on Xiaomi/Lenovo everything is ok. probably triggered by unstable connection

baidala avatar Nov 08 '19 13:11 baidala

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

balsikandar-okcredit avatar Feb 25 '20 19:02 balsikandar-okcredit

I set up for you a server with the golang server the endpoint is https://myvoip.w3france.com:10443/item/2 in POST For reasons I can't explain, there are less protocol problem with the server (about 3/4%) vs my dev machine on the same wifi network (in that case I use 4G) And last information, I have a OnePlus 5T with Android 9. Didn't try it from other device.

Retrofit.Builder builder =
                new Retrofit.Builder()
                        .baseUrl("https://myvoip.w3france.com:10443/")
                        .addConverterFactory(GsonConverterFactory.create());

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1));
        Retrofit retrofit = builder.client(httpClient.build()).build();

        AuthService service = retrofit.create(AuthService.class);

        // iterate over each item of the nomtable
        for (int i = 0; i < 500; i++) {
                final String id = Integer.toString(i);

                RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), "");

                Call<String> call = service.sendItem(id, body);

                call.enqueue(new Callback<String>() {
                    @Override
                    public void onResponse(Call<String> call, Response<String> response) {
                        Log.d(TAG, "Success " + id);

                    }

                    @Override
                    public void onFailure(Call<String> call, Throwable t) {
                        Log.d(TAG, "Failure " + id);
                        Log.d(TAG, t.getMessage());
                        t.printStackTrace();
                    }
                });
        }

and AuthService.java

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Path;

public interface AuthService {
    @POST("item/{item}")
    Call<String> sendItem(
            @Path("item") String itemGuid,
            @Body RequestBody body);
}

yeah face same issue in Oneplus 5T

Charuwaka avatar Apr 23 '20 07:04 Charuwaka

i have this issue

easazade avatar May 06 '20 14:05 easazade

I want to check if we are indeed receiving RST_STREAM frame on an Android client. The instructions in this link doesn't seem to work anymore. https://square.github.io/okhttp/debug_logging/ How can I enable frame logging for Android client?

shrutigupta23 avatar May 28 '20 11:05 shrutigupta23

Thanks for flagging, I'll fix the instructions. Will answer this evening, if noone else beats me to it.

yschimke avatar May 28 '20 12:05 yschimke

@shrutigupta23 In theory now, all that should be required to enable framelogging via adb is the following

$ adb shell setprop log.tag.okhttp.Http2 DEBUG
$ adb logcat '*:E' 'okhttp.Http2:D'
...
05-28 19:31:32.365  8472  8505 D okhttp.Http2: >> CONNECTION 505249202a20485454502f322e300d0a0d0a534d0d0a0d0a
05-28 19:31:32.366  8472  8505 D okhttp.Http2: >> 0x00000000     6 SETTINGS
05-28 19:31:32.368  8472  8505 D okhttp.Http2: >> 0x00000000     4 WINDOW_UPDATE
05-28 19:31:32.374  8472  8509 D okhttp.Http2: << 0x00000000    18 SETTINGS
05-28 19:31:32.374  8472  8509 D okhttp.Http2: << 0x00000000     4 WINDOW_UPDATE
05-28 19:31:32.379  8472  8505 D okhttp.Http2: >> 0x00000003    45 HEADERS       END_STREAM|END_HEADERS
05-28 19:31:32.382  8472  8510 D okhttp.Http2: >> 0x00000000     0 SETTINGS      ACK
05-28 19:31:32.389  8472  8509 D okhttp.Http2: << 0x00000000     0 SETTINGS      ACK
05-28 19:31:32.408  8472  8509 D okhttp.Http2: << 0x00000003   373 HEADERS       END_HEADERS
05-28 19:31:32.412  8472  8509 D okhttp.Http2: << 0x00000003   230 DATA          END_STREAM
05-28 19:31:32.412  8472  8509 D okhttp.Http2: << 0x00000000     8 PING
05-28 19:31:32.413  8472  8511 D okhttp.Http2: >> 0x00000000     8 PING          ACK
05-28 19:31:32.523  8472  8505 D okhttp.Http2: >> CONNECTION 505249202a20485454502f322e300d0a0d0a534d0d0a0d0a
05-28 19:31:32.524  8472  8505 D okhttp.Http2: >> 0x00000000     6 SETTINGS
05-28 19:31:32.525  8472  8505 D okhttp.Http2: >> 0x00000000     4 WINDOW_UPDATE
05-28 19:31:32.529  8472  8505 D okhttp.Http2: >> 0x00000003    49 HEADERS       END_STREAM|END_HEADERS
05-28 19:31:32.556  8472  8512 D okhttp.Http2: << 0x00000000    18 SETTINGS
05-28 19:31:32.556  8472  8512 D okhttp.Http2: << 0x00000000     4 WINDOW_UPDATE
05-28 19:31:32.557  8472  8512 D okhttp.Http2: << 0x00000000     0 SETTINGS      ACK
05-28 19:31:32.557  8472  8511 D okhttp.Http2: >> 0x00000000     0 SETTINGS      ACK
05-28 19:31:32.564  8472  8512 D okhttp.Http2: << 0x00000003   375 HEADERS       END_HEADERS
05-28 19:31:32.568  8472  8512 D okhttp.Http2: << 0x00000003  1841 DATA          PADDED
05-28 19:31:32.568  8472  8512 D okhttp.Http2: << 0x00000003    15 DATA          END_STREAM|PADDED
05-28 19:31:32.569  8472  8512 D okhttp.Http2: << 0x00000000     8 PING
05-28 19:31:32.569  8472  8510 D okhttp.Http2: >> 0x00000000     8 PING          ACK

yschimke avatar May 28 '20 18:05 yschimke

But the instructions you linked are broken for Java also, the path of the link changed. I'll update that as well.

yschimke avatar May 28 '20 18:05 yschimke

Happens randomly with OkHttp3 too, using Amazon CloudFront in HTTP/2 mode. Most likely related to slow network connection.

wellu avatar Jun 16 '20 09:06 wellu

okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL The same problem happened in Http2, the okhttp version is 3.14.9, does it have a solution?

vanminh2501 avatar Jul 30 '20 10:07 vanminh2501

You can check you are not calling cancel() too early.

IIRC, I had that issue because I made a mistake in an extension where I was calling cancel after a successful response, which would make reading it fail with this exception.

LouisCAD avatar Jul 30 '20 11:07 LouisCAD

You can check you are not calling cancel() too early.

IIRC, I had that issue because I made a mistake in an extension where I was calling cancel after a successful response, which would make reading it fail with this exception.

@LouisCAD Thanks, but I'm not using cacel() in my code, it happens always when there is bad connection.

vanminh2501 avatar Jul 30 '20 14:07 vanminh2501

You can check you are not calling cancel() too early. IIRC, I had that issue because I made a mistake in an extension where I was calling cancel after a successful response, which would make reading it fail with this exception.

@LouisCAD Thanks, but I'm not using cacel() in my code, it happens always when there is bad connection.

@vanminh2501 You resolved this problem? I'm having this in this week.

phelipepalte avatar Nov 27 '20 18:11 phelipepalte

Having the same issue, random

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

on v 3.12

goacoustic avatar Dec 12 '20 05:12 goacoustic

@goacoustic please provide frame logging or event listener logging so we can investigate, this one line doesn't help investigate. Thanks, this would be really helpful.

https://square.github.io/okhttp/events/

yschimke avatar Dec 12 '20 13:12 yschimke

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)

Rafhack avatar Dec 21 '20 17:12 Rafhack