Nginx uwsgi (104: Connection reset by peer) while reading response header from upstream

前端 未结 8 2230
感动是毒
感动是毒 2020-12-12 23:34

Environment is Nginx + uwsgi.

Getting a 502 bad gateway error from Nginx on certain GET requests. Seems to be related to the length of the URL. In our particular cas

8条回答
  •  囚心锁ツ
    2020-12-13 00:18

    When we receive a message like (104: Connection reset by peer) while reading response header from upstream, most often, we could blame the upstream side of this kind of error.

    As described, the connection was reset by the upstream peer, not by nginx itself. Nginx as a client can barely do anything to make it right.

    I'm suspecting if modifying buffer-size will do the magic. Basically the command changes the buffer size where response headers are cached. This would take effect when the response header is too big, of which case we receive a message saying upstream sent too big header while reading response header from upstream, and that is totally different thing from connection reset by peer.

    Since this kind of error is trigger randomly, I would suggest you check whether nginx uses keepalive when talking to upstreams. If this was the case, the connection might be reset by upstream server when the idle timed out whereas nginx had no idea that the connection had been dropped, hence forwarding the request using the same connection.

    There's no elegant solution to fix it as far as I know. You could do retry or set a keepalive_timeout value to the upstream connection pool in nginx to avoid the problem.

    referencing:

    Apache HttpClient Interim Error: NoHttpResponseException

    http://tengine.taobao.org/document/http_upstream_keepalive_timeout.html

提交回复
热议问题