{
  "id": "nginx/worker-connections-are-not-enough-while-connecting-to-upstream",
  "signature": "nginx: [alert] 1024 worker_connections are not enough while connecting to upstream",
  "signature_zh": "nginx：[警报] 1024 个工作连接不足以连接到上游",
  "regex": "nginx: \\[alert\\] \\d+ worker_connections are not enough while connecting to upstream",
  "domain": "nginx",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "The number of simultaneous connections exceeds the worker_connections limit, causing connection failures to upstream servers.",
  "root_cause_type": "generic",
  "root_cause_zh": "同时连接数超过了 worker_connections 限制，导致连接上游服务器失败。",
  "versions": [
    {
      "version": "nginx 1.24.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.22.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.20.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.18.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "System limits (ulimit -n, fs.file-max) may still cap the total connections; also the OS may have per-process limits.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "While it reduces connection duration, it increases connection churn and may still hit the limit under high concurrency.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Multi_accept affects connection acceptance behavior but does not increase the maximum number of connections.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Increase worker_connections and adjust system limits:\nevents {\n    worker_connections 4096;\n    multi_accept on;\n}\nAlso increase system max open files: ulimit -n 65536 and set in /etc/security/limits.conf:\n* soft nofile 65536\n* hard nofile 65536\nThen reload nginx.",
      "success_rate": 0.85,
      "how": "Increase worker_connections and adjust system limits:\nevents {\n    worker_connections 4096;\n    multi_accept on;\n}\nAlso increase system max open files: ulimit -n 65536 and set in /etc/security/limits.conf:\n* soft nofile 65536\n* hard nofile 65536\nThen reload nginx.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase the number of worker_processes to distribute connections:\nworker_processes auto;\nThis uses all CPU cores; each worker has its own connection pool.",
      "success_rate": 0.8,
      "how": "Increase the number of worker_processes to distribute connections:\nworker_processes auto;\nThis uses all CPU cores; each worker has its own connection pool.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement rate limiting or connection limiting per IP to prevent abuse:\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\nlimit_conn addr 100;\nThis caps connections per client to stay within worker_connections.",
      "success_rate": 0.7,
      "how": "Implement rate limiting or connection limiting per IP to prevent abuse:\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\nlimit_conn addr 100;\nThis caps connections per client to stay within worker_connections.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "增加 worker_connections 并调整系统限制：\nevents {\n    worker_connections 4096;\n    multi_accept on;\n}\n同时增加系统最大打开文件数：ulimit -n 65536 并在 /etc/security/limits.conf 中设置：\n* soft nofile 65536\n* hard nofile 65536\n然后重新加载 nginx。",
    "增加 worker_processes 数量以分配连接：\nworker_processes auto;\n这将使用所有 CPU 核心；每个 worker 有自己的连接池。",
    "实施速率限制或按 IP 限制连接以防止滥用：\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\nlimit_conn addr 100;\n这将限制每个客户端的连接数，以保持在 worker_connections 范围内。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nginx.org/en/docs/ngx_core_module.html#worker_connections",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-09-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}