square/okhttp

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

Closed this issue · 8 comments

smi22 commented

Api call with retrofit and rxandroid

Depencency used:
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'

Here is setup:
public static IAPIInterface getRestAdapterForRx() {

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.addInterceptor(logging);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(httpClient.build())
            .build();

    return retrofit.create(IAPIInterface.class);
}

Mostly, API Call gives response but some time it give this error.

Typically error code is sent by a server to indicate a problem server-side. It could also happen if OkHttp’s stream reader crashes with an unexpected exception.

Could you provide a standalone test case? As-is there’s no action we can take on this.

A sample project to reproduce this error can be found here https://github.com/tobydigz/TestRetrofitApp

What I know so far is that

  • I only get this error when I receive a 401 while attempting a GET. Might be due to the server I don't know.
  • The logging interceptor cuts off abruptly but when I try the same endpoint from Postman, I get a response body.

I could also provide a base url if that's necessary, to help with pinpointing the error

So dependencies used are

  • implementation "com.squareup.okhttp3:okhttp:3.13.1"
  • implementation "com.squareup.retrofit2:retrofit:2.3.0"
  • implementation "com.squareup.okhttp3:logging-interceptor:3.13.1"
  • implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
  • implementation "com.squareup.retrofit2:converter-moshi:2.3.0"
  • implementation "io.reactivex.rxjava2:rxjava:2.1.7"
  • implementation "io.reactivex.rxjava2:rxkotlin:2.1.0"
  • implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
  • implementation "com.squareup.moshi:moshi-kotlin:1.8.0"

Is postman using HTTP/2? I think it's a server-triggered failure.

Is postman using HTTP/2? I think it's a server-triggered failure.

I'm not sure but when I set Okhttp to use HTTP/1.1 I get End Of File Exception instead.
Also an Angular and C client interacting with this endpoint don't experience this issue, just the Android client

Can you isolate the difference? Maybe send the C client’s headers with OkHttp?

Is postman using HTTP/2? I think it's a server-triggered failure.

I am facing the same problem when the response code is 503. Postman and ios client do not get anything like this error. Client headers are the same.

Can you explain "server-triggered" failure?

What's the problem?? ... I can't find the solution. Using Http1.1 gets close error.

I found that the server can't send all data properly. For instance, JSON isn't complete(the braces aren't closed properly at the end). It's server problem. I guess it's instance problem. the instance must have some limit for that. So, you need to enlarge the size.

ex.

{
"name": "john",
"address": "a b c",
... // at 3000th lines
"na // end with incompletely

the rest of it is missing.

UPDATE

it was Nginx buffer size problem.

If you are using AWS EC2,

Go to /etc/nginx/default.d/server.conf

proxy_redirect off;
proxy_buffering off;