{
  "id": "go/http-request-canceled-context",
  "signature": "Get \"https://api.example.com/data\": context deadline exceeded",
  "signature_zh": "Get \"https://api.example.com/data\"：上下文截止时间已超过",
  "regex": "Get\\ \"https://api\\.example\\.com/data\":\\ context\\ deadline\\ exceeded",
  "domain": "go",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The http.Client request context timed out or was canceled before the server responded. Often caused by a too-short context.WithTimeout, a slow upstream, or reusing a canceled context across requests.",
  "root_cause_type": "generic",
  "root_cause_zh": "http.Client 请求的上下文在服务器响应前超时或被取消。常见原因：context.WithTimeout 设置过短、上游过慢，或在多个请求间复用了已取消的 context。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "If the deadline comes from the request context, the client Timeout is irrelevant; the context still fires first.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Retrying with the same canceled context immediately fails again and amplifies load.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\nreq, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)\nresp, err := client.Do(req)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Use context.WithoutCancel(parentCtx) when a downstream call must outlive the parent request lifetime.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}