OkHttp keeps getting StreamResetException: stream was reset: INTERNAL_ERROR when it's 200

你离开我真会死。 提交于 2021-02-10 16:23:58

问题


I got StreamResetException: stream was reset: INTERNAL_ERROR from OkHttp. What's the problem?

Here's the logs.

I/okhttp.OkHttpClient: <-- 200 https://www.example.com/user/list (396ms)
I/okhttp.OkHttpClient: date: Fri, 04 Dec 2020 02:21:35 GMT
I/okhttp.OkHttpClient: content-type: application/json
I/okhttp.OkHttpClient: content-length: 99730
I/okhttp.OkHttpClient: server: nginx/1.18.0
I/okhttp.OkHttpClient: allow: GET, HEAD, OPTIONS
I/okhttp.OkHttpClient: x-frame-options: DENY
I/okhttp.OkHttpClient: x-content-type-options: nosniff
I/okhttp.OkHttpClient: referrer-policy: same-origin
D/okhttp.Http2: << 0x00000003  5792 DATA          
D/okhttp.Http2: << 0x00000003     4 RST_STREAM    
D/okhttp.TaskRunner: Q10092 canceled              : OkHttp ConnectionPool
D/force: okhttp3.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
D/okhttp.Http2: >> 0x00000000     8 GOAWAY     
D/okhttp.TaskRunner: Q10096 finished run in 216 ms: OkHttp www.example.com

This is issued in Okhttp Gihub Repository. But any issues haven't solved yet.

I called the API like this

    @Headers("Content-Type: application/json")
    @GET("/user/list")
    fun getUserList(@Header("Authorization") jwt: String): Call<ArrayList<UserData>>

It's 200 but I get nothing. It's very weird behaviour..

Is it a server problem or my problem? (The server is Django).


回答1:


As suggested in OkHttp issue tracker, mostly likely this is a server error after the headers are sent.

https://github.com/square/okhttp/issues/3936

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.

I'd suggest checking for server errors if you can, but you can see the Http2 frame from the server here

D/okhttp.Http2: << 0x00000003     4 RST_STREAM  



回答2:


it was Nginx buffer size problem.

If you are using AWS EC2,

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

And set,

proxy_redirect off;
proxy_buffering off;


来源:https://stackoverflow.com/questions/65137191/okhttp-keeps-getting-streamresetexception-stream-was-reset-internal-error-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!