{
  "id": "cloud/azure-functions-dynamic-sku-sql-connection-pool-exhausted",
  "signature": "System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.",
  "signature_zh": "System.InvalidOperationException：超时已过期。在从池中获取连接之前，超时期限已过。这可能是因为所有池化连接都在使用中并且已达到最大池大小。",
  "regex": "Timeout expired\\. The timeout period elapsed prior to obtaining a connection from the pool",
  "domain": "cloud",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "Azure Functions on the Consumption (dynamic) plan scale out rapidly under load, creating many concurrent instances that exhaust the SQL Database connection pool (default max pool size = 100) because each instance opens new connections without reusing them efficiently.",
  "root_cause_type": "generic",
  "root_cause_zh": "消耗（动态）计划中的 Azure Functions 在负载下快速扩展，创建许多并发实例，这些实例耗尽了 SQL 数据库连接池（默认最大池大小 = 100），因为每个实例都会打开新连接而无法有效重用。",
  "versions": [
    {
      "version": "Azure Functions runtime v4 (.NET 8)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Azure SQL Database (DTU-based S2 tier)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "System.Data.SqlClient 4.8.6",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The issue is connection pooling, not the SQL query itself; optimizing a single query won't reduce the number of concurrent connections.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The function timeout is separate from the SQL connection timeout; increasing it does not affect pool exhaustion.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Scaling up to a higher SKU may help but is often unnecessary and costly; the root cause is connection management, not database capacity.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Increase the Max Pool Size in the connection string to accommodate more concurrent connections (e.g., add 'Max Pool Size=200'): `Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypwd;Max Pool Size=200;`",
      "success_rate": 0.85,
      "how": "Increase the Max Pool Size in the connection string to accommodate more concurrent connections (e.g., add 'Max Pool Size=200'): `Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypwd;Max Pool Size=200;`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement connection multiplexing by using a singleton HttpClient or Dapper with a shared DbConnection in the Azure Functions startup class to reuse connections across invocations.",
      "success_rate": 0.8,
      "how": "Implement connection multiplexing by using a singleton HttpClient or Dapper with a shared DbConnection in the Azure Functions startup class to reuse connections across invocations.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Increase the Max Pool Size in the connection string to accommodate more concurrent connections (e.g., add 'Max Pool Size=200'): `Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypwd;Max Pool Size=200;`",
    "Implement connection multiplexing by using a singleton HttpClient or Dapper with a shared DbConnection in the Azure Functions startup class to reuse connections across invocations."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.microsoft.com/en-us/azure/azure-functions/manage-connections",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-06-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}