{
  "id": "api/http-504-gateway-timeout-upstream",
  "signature": "504 Gateway Timeout: upstream response timeout",
  "signature_zh": "504 网关超时：上游响应超时",
  "regex": "504\\s+Gateway\\s+Timeout:\\s+upstream\\s+response\\s+timeout",
  "domain": "api",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "An API gateway or reverse proxy (e.g., Nginx, AWS API Gateway) timed out while waiting for the upstream service to respond, typically due to slow processing or network issues.",
  "root_cause_type": "generic",
  "root_cause_zh": "API 网关或反向代理（如 Nginx、AWS API Gateway）在等待上游服务响应时超时，通常由于处理缓慢或网络问题。",
  "versions": [
    {
      "version": "Nginx 1.25.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "AWS API Gateway (2024)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Kong 3.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "HAProxy 2.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The timeout occurs at the gateway, not the client; client-side changes are irrelevant.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Restarting resets the service but does not address underlying performance bottlenecks like slow queries or resource leaks.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Removing timeouts allows slow requests to accumulate, potentially crashing the service.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Increase the upstream timeout in the gateway configuration. For Nginx, add to the location block: `proxy_read_timeout 60s; proxy_connect_timeout 30s;`. Then reload: `nginx -s reload`.",
      "success_rate": 0.85,
      "how": "Increase the upstream timeout in the gateway configuration. For Nginx, add to the location block: `proxy_read_timeout 60s; proxy_connect_timeout 30s;`. Then reload: `nginx -s reload`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Optimize the upstream service's response time by adding caching, database query optimization, or asynchronous processing. For example, use Redis caching for frequent queries.",
      "success_rate": 0.8,
      "how": "Optimize the upstream service's response time by adding caching, database query optimization, or asynchronous processing. For example, use Redis caching for frequent queries.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a retry mechanism with exponential backoff in the client, but ensure idempotency. Example in Python: `requests.get(url, timeout=10); time.sleep(2**attempt)`.",
      "success_rate": 0.75,
      "how": "Implement a retry mechanism with exponential backoff in the client, but ensure idempotency. Example in Python: `requests.get(url, timeout=10); time.sleep(2**attempt)`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Increase the upstream timeout in the gateway configuration. For Nginx, add to the location block: `proxy_read_timeout 60s; proxy_connect_timeout 30s;`. Then reload: `nginx -s reload`.",
    "Optimize the upstream service's response time by adding caching, database query optimization, or asynchronous processing. For example, use Redis caching for frequent queries.",
    "Implement a retry mechanism with exponential backoff in the client, but ensure idempotency. Example in Python: `requests.get(url, timeout=10); time.sleep(2**attempt)`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504",
  "official_doc_section": null,
  "error_code": "504",
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2025-03-10",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}