{
  "id": "go/close-of-receive-only-channel",
  "signature": "error: cannot close receive-only channel ch (variable of type <-chan int)",
  "signature_zh": "error：无法关闭只接收 channel ch（类型为 <-chan int 的变量）",
  "regex": "error:\\ cannot\\ close\\ receive\\-only\\ channel\\ ch\\ \\(variable\\ of\\ type\\ <\\-chan\\ int\\)",
  "domain": "go",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "The compiler rejects close() on a receive-only channel type. This surfaces when a function signature returns <-chan T but the implementation tries to close it internally.",
  "root_cause_type": "generic",
  "root_cause_zh": "编译器拒绝对只接收 channel 类型调用 close()。常见于函数返回 <-chan T，但实现内部试图关闭该 channel。",
  "versions": [
    {
      "version": "1.18",
      "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": "Type conversion doesn't change directionality for close; the compiler still rejects it because the static type is receive-only.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Receivers ranging over the channel will block forever waiting for a close that never comes.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "func producer() <-chan int {\n    ch := make(chan int)\n    go func() {\n        defer close(ch)\n        // send...\n    }()\n    return ch\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "func producer(done <-chan struct{}) <-chan int {\n    ch := make(chan int)\n    go func() {\n        defer close(ch)\n        select { case <-done: return; default: }\n    }()\n    return ch\n}",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}