{
  "id": "api/http-502-bad-gateway-upstream-connection-reset",
  "signature": "502 Bad Gateway: upstream connection reset by peer",
  "signature_zh": "502 错误网关：上游连接被对端重置",
  "regex": "502 Bad Gateway: upstream connection reset by peer",
  "domain": "api",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The upstream server (e.g., application backend) abruptly closed the TCP connection while the proxy (e.g., NGINX, ALB) was trying to forward the request, often due to a crash, timeout, or firewall rule.",
  "root_cause_type": "generic",
  "root_cause_zh": "上游服务器（例如应用程序后端）在代理（例如 NGINX、ALB）尝试转发请求时突然关闭了 TCP 连接，通常是由于崩溃、超时或防火墙规则。",
  "versions": [
    {
      "version": "NGINX 1.24+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "AWS ALB 2023+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "HAProxy 2.8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Gunicorn 21+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "uWSGI 2.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The reset is immediate, not due to a slow response.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The upstream server is the root cause.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check upstream server logs for application crashes or resource exhaustion. For example, in a Python Gunicorn setup, look for 'Worker failed to boot' or 'Out of memory'. Increase the number of workers or memory limits. Example command to add more workers:\ngunicorn --workers=4 --timeout=120 myapp:app",
      "success_rate": 0.85,
      "how": "Check upstream server logs for application crashes or resource exhaustion. For example, in a Python Gunicorn setup, look for 'Worker failed to boot' or 'Out of memory'. Increase the number of workers or memory limits. Example command to add more workers:\ngunicorn --workers=4 --timeout=120 myapp:app",
      "condition": "",
      "sources": []
    },
    {
      "action": "Verify firewall rules between proxy and upstream. On Linux, use iptables to check for dropped packets:\niptables -L -n -v | grep DROP\nIf rules are blocking, add an allow rule for the proxy IP on the upstream's port (e.g., port 8080).",
      "success_rate": 0.8,
      "how": "Verify firewall rules between proxy and upstream. On Linux, use iptables to check for dropped packets:\niptables -L -n -v | grep DROP\nIf rules are blocking, add an allow rule for the proxy IP on the upstream's port (e.g., port 8080).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Check upstream server logs for application crashes or resource exhaustion. For example, in a Python Gunicorn setup, look for 'Worker failed to boot' or 'Out of memory'. Increase the number of workers or memory limits. Example command to add more workers:\ngunicorn --workers=4 --timeout=120 myapp:app",
    "Verify firewall rules between proxy and upstream. On Linux, use iptables to check for dropped packets:\niptables -L -n -v | grep DROP\nIf rules are blocking, add an allow rule for the proxy IP on the upstream's port (e.g., port 8080)."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass",
  "official_doc_section": null,
  "error_code": "502",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-10-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}