{
  "id": "go/goroutine-leak-http-request",
  "signature": "error: net/http: request canceled (Client.Timeout exceeded while awaiting headers)",
  "signature_zh": "错误：net/http：请求被取消（等待响应头时超过客户端超时）",
  "regex": "error:\\ net/http:\\ request\\ canceled\\ \\(Client\\.Timeout\\ exceeded\\ while\\ awaiting\\ headers\\)",
  "domain": "go",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "An HTTP client call without a context or timeout blocked indefinitely, leaving the goroutine leaked and the request canceled by the client timeout.",
  "root_cause_type": "generic",
  "root_cause_zh": "未带上下文或超时的 HTTP 客户端调用无限阻塞，导致 goroutine 泄漏，最终被客户端超时取消。",
  "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": "Leaks the goroutine longer; the root cause is missing cancellation.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "http.Get uses DefaultClient with no timeout; can block forever.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\nreq, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)\nresp, err := http.DefaultClient.Do(req)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "client := &http.Client{Timeout: 5 * time.Second}\nresp, err := client.Get(url)",
      "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-10-07",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}