nginx network_error ai_generated partial

upstream connection reset by peer while reading response header from upstream

ID: nginx/upstream-connection-reset-by-peer

Also available as: JSON · Markdown · 中文
82%Fix Rate
83%Confidence
1Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.18.0 active
nginx 1.20.2 active
nginx 1.22.1 active
nginx 1.24.0 active
nginx 1.25.3 active

Root Cause

The upstream server forcibly closes the TCP connection (RST packet) before sending a complete response, often due to application crash or timeout.

generic

中文

上游服务器在发送完整响应之前强制关闭TCP连接(RST包),通常由应用程序崩溃或超时引起。

Official Documentation

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream

Workarounds

  1. 85% success Check upstream application logs for crashes or timeouts; fix the application to handle requests gracefully
    Check upstream application logs for crashes or timeouts; fix the application to handle requests gracefully
  2. 80% success Add retry logic with proxy_next_upstream: proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
    Add retry logic with proxy_next_upstream: proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  3. 60% success Increase upstream keepalive settings to reduce connection churn: keepalive 32;
    Increase upstream keepalive settings to reduce connection churn: keepalive 32;

中文步骤

  1. 检查上游应用程序日志中的崩溃或超时;修复应用程序以优雅处理请求
  2. 使用proxy_next_upstream添加重试逻辑:proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  3. 增加上游keepalive设置以减少连接变更:keepalive 32;

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Connection timeout only affects initial handshake, not response reading; RST occurs after connection is established.

  2. 70% fail

    HTTP version change may affect keepalive but doesn't prevent RST from upstream.

  3. 65% fail

    This disables keepalive but upstream may still send RST if it crashes.