{
  "id": "go/race-detector-in-test",
  "signature": "panic: race detected during execution of test",
  "signature_zh": "panic: 执行测试期间检测到竞争",
  "regex": "panic:\\ race\\ detected\\ during\\ execution\\ of\\ test",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A test running under -race spawns goroutines that share state without synchronization, and the race detector aborts the test binary.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 -race 下运行的测试启动了共享状态且无同步的 goroutine，竞争检测器中止了测试二进制。",
  "versions": [
    {
      "version": "1.1+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Shuffling changes timing but the unsynchronized access remains and the race recurs.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The race is inside the test's own goroutines, not between tests, so serializing tests does not help.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "var wg sync.WaitGroup\nwg.Add(1)\ngo func() { defer wg.Done(); mutateShared() }()\nwg.Wait()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "go test -race -run TestFoo ./...\n// read the two conflicting stacks and add a mutex around both",
      "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-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}