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

3

2

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:

  • Nexus 4, Android 5.1.1 (official)
  • Nexus 9, Android 7.0 (official)
  • Samsung Galaxy S3, Android 4.4 (official)

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)
Electrolysis answered 28/10, 2016 at 20:42 Comment(0)
E
1

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).

Electrolysis answered 28/10, 2016 at 20:51 Comment(0)
D
2

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'
Dentelle answered 10/9, 2018 at 13:31 Comment(0)
E
1

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).

Electrolysis answered 28/10, 2016 at 20:51 Comment(0)
C
1

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.

Carrell answered 13/1, 2017 at 2:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.