artem
artem

Reputation: 16777

java.io.IOException: stream was reset: REFUSED_STREAM on several devices

I'm using Retrofit 1.9 in my Android app.

Server is on Django with Nginx, HTTPS with HTTP 2. Certificate is from WoSign, "A" score on SSL Labs.

I'm testing on 3 devices:

On SGS3 it works fine, but on Nexus 4 & 9 I'm getting the exception:

java.io.IOException: stream was reset: REFUSED_STREAM
                                                               at com.squareup.okhttp.internal.framed.FramedStream.getResponseHeaders(FramedStream.java:146)
                                                               at com.squareup.okhttp.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:150)
                                                               at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
                                                               at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87)
                                                               at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722)
                                                               at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
                                                               at com.squareup.okhttp.Call.getResponse(Call.java:287)
                                                               at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
                                                               at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
                                                               at com.squareup.okhttp.Call.execute(Call.java:80)
                                                               at retrofit.client.OkClient.execute(OkClient.java:53)
                                                               at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
                                                               at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
                                                               at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
                                                               at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                               at retrofit.Platform$Android$2$1.run(Platform.java:142)
                                                               at java.lang.Thread.run(Thread.java:761)

Upvotes: 2

Views: 4671

Answers (3)

Tejas Pandya
Tejas Pandya

Reputation: 4087

If anyone is still having a problem (2018).

I've solved that issue by updating retrofit version to

 implementation 'com.squareup.retrofit2:retrofit:2.4.0'

Upvotes: 2

DiscDev
DiscDev

Reputation: 39052

In my case, nginx was already updated to 1.11.x. The culprit for me was okhttp and retrofit. When I tried to make a PUT request, it would fail with stream was reset: REFUSED_STREAM.

To fix it, I upgraded to the latest versions of both, which at the time I'm writing this are:

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.5.0'

If you're using retrofit 2.0.x or okhttp 3.1.x, upgrading should fix the issue.

Upvotes: 1

artem
artem

Reputation: 16777

I've solved this. It's a Nginx bug

This issue was fixed in Nginx 1.11. So, the solution is just to update to NGINX 1.11 (mainline currently).

Upvotes: 1

Related Questions