{
  "id": "go/context-canceled-in-goroutine-pool",
  "signature": "context canceled: goroutine pool worker detected cancellation after returning result",
  "signature_zh": "上下文已取消：goroutine 池工作线程在返回结果后检测到取消",
  "regex": "context canceled: goroutine pool worker detected cancellation",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A goroutine in a pool checks context cancellation after computing a result, causing a false positive cancellation error when the parent context is cancelled just before the worker returns.",
  "root_cause_type": "generic",
  "root_cause_zh": "goroutine 池中的工作线程在计算结果后检查上下文取消，当父上下文在工作线程返回前被取消时，导致假阳性取消错误。",
  "versions": [
    {
      "version": "Go 1.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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"
    },
    {
      "version": "Go 1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Without context checks, workers cannot be cancelled mid-task, leading to resource leaks and slow shutdowns.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the parent context is cancelled, derived contexts are also cancelled; doesn't solve the race condition.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Mutexes don't prevent the race between context cancellation and result computation; can cause deadlocks.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check context cancellation before computation, not after; use select with both context.Done() and result channel",
      "success_rate": 0.9,
      "how": "Check context cancellation before computation, not after; use select with both context.Done() and result channel",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a sync.WaitGroup or atomic flag to ensure result is fully sent before checking cancellation",
      "success_rate": 0.85,
      "how": "Use a sync.WaitGroup or atomic flag to ensure result is fully sent before checking cancellation",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore cancellation error if result was successfully computed and sent; log but don't propagate",
      "success_rate": 0.8,
      "how": "Ignore cancellation error if result was successfully computed and sent; log but don't propagate",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Check context cancellation before computation, not after; use select with both context.Done() and result channel",
    "Use a sync.WaitGroup or atomic flag to ensure result is fully sent before checking cancellation",
    "Ignore cancellation error if result was successfully computed and sent; log but don't propagate"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/context#Context",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}