{
  "id": "database/mongodb-connection-pool-timeout",
  "signature": "pymongo.errors.ServerSelectionTimeoutError: connection closed, Timeout: 30s",
  "signature_zh": "pymongo.errors.ServerSelectionTimeoutError：连接已关闭，超时：30秒",
  "regex": "pymongo\\.errors\\.ServerSelectionTimeoutError: connection closed, Timeout: \\d+s",
  "domain": "database",
  "category": "connection_error",
  "subcategory": null,
  "root_cause": "MongoDB driver's server selection timeout occurs when all connections in the pool are closed or exhausted, often due to network interruptions, server overload, or connection pool misconfiguration in the application.",
  "root_cause_type": "generic",
  "root_cause_zh": "当连接池中的所有连接都已关闭或耗尽时，MongoDB 驱动程序的服务器选择超时发生，通常由网络中断、服务器过载或应用程序中的连接池配置错误引起。",
  "versions": [
    {
      "version": "MongoDB 5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This only delays failure; if connections are genuinely closed, the timeout will eventually trigger anyway, and the application remains unresponsive longer.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The same configuration or network problem persists; the error will reappear shortly after restart.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This prevents connection reuse, causing new connections for every operation, which increases latency and may exhaust server resources.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set MongoClient options: client = MongoClient('mongodb://localhost:27017', maxPoolSize=50, minPoolSize=10, retryWrites=True, retryReads=True). This ensures connections are maintained and operations retry on failure.",
      "success_rate": 0.85,
      "how": "Set MongoClient options: client = MongoClient('mongodb://localhost:27017', maxPoolSize=50, minPoolSize=10, retryWrites=True, retryReads=True). This ensures connections are maintained and operations retry on failure.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use MongoDB drivers' built-in heartbeat monitoring: MongoClient('mongodb://localhost:27017', heartbeatFrequencyMS=10000). This detects closed connections and reconnects automatically.",
      "success_rate": 0.8,
      "how": "Use MongoDB drivers' built-in heartbeat monitoring: MongoClient('mongodb://localhost:27017', heartbeatFrequencyMS=10000). This detects closed connections and reconnects automatically.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrap database calls in a retry decorator: import time; from pymongo.errors import ServerSelectionTimeoutError; def retry_on_timeout(func): for attempt in range(3): try: return func() except ServerSelectionTimeoutError: time.sleep(2**attempt); raise.",
      "success_rate": 0.9,
      "how": "Wrap database calls in a retry decorator: import time; from pymongo.errors import ServerSelectionTimeoutError; def retry_on_timeout(func): for attempt in range(3): try: return func() except ServerSelectionTimeoutError: time.sleep(2**attempt); raise.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Set MongoClient options: client = MongoClient('mongodb://localhost:27017', maxPoolSize=50, minPoolSize=10, retryWrites=True, retryReads=True). This ensures connections are maintained and operations retry on failure.",
    "Use MongoDB drivers' built-in heartbeat monitoring: MongoClient('mongodb://localhost:27017', heartbeatFrequencyMS=10000). This detects closed connections and reconnects automatically.",
    "Wrap database calls in a retry decorator: import time; from pymongo.errors import ServerSelectionTimeoutError; def retry_on_timeout(func): for attempt in range(3): try: return func() except ServerSelectionTimeoutError: time.sleep(2**attempt); raise."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/drivers/pymongo/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}