{
  "id": "go/http-response-body-not-closed",
  "signature": "http: read on closed response body",
  "signature_zh": "HTTP：在已关闭的响应体上执行读取操作",
  "regex": "http: read on closed response body",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to read from an http.Response.Body after it has already been closed, typically due to premature closing or multiple goroutines sharing the body.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 http.Response.Body 已经被关闭后尝试从中读取数据，通常是由于过早关闭或多个协程共享该 body 导致。",
  "versions": [
    {
      "version": "Go 1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Closing the body before reading makes the data unavailable; the body must be read first, then closed.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the body is already closed, ReadAll will panic; always check errors and ensure body is open.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Always defer resp.Body.Close() after checking for error, and read the body inside the defer scope",
      "success_rate": 0.95,
      "how": "Always defer resp.Body.Close() after checking for error, and read the body inside the defer scope",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a sync.Once or mutex if multiple goroutines need to read the same body",
      "success_rate": 0.85,
      "how": "Use a sync.Once or mutex if multiple goroutines need to read the same body",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在检查错误后始终 defer resp.Body.Close()，并在 defer 作用域内读取 body",
    "如果多个协程需要读取同一个 body，使用 sync.Once 或互斥锁"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/net/http#Response",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-04-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}