{
  "id": "go/panic-timer-reset-negative-duration",
  "signature": "panic: time: Reset called on timer with negative duration",
  "signature_zh": "恐慌：对具有负持续时间的计时器调用 Reset",
  "regex": "panic: time: Reset called on timer with negative duration",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling Timer.Reset() with a negative duration value causes a runtime panic in Go's time package.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用负持续时间值调用 Timer.Reset() 会导致 Go 的 time 包中的运行时恐慌。",
  "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": "time.Duration() does not validate sign; negative values remain negative.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "time.AfterFunc() also panics on negative duration; same underlying issue.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Panic recovery masks the bug but timer state is corrupted; leads to unpredictable behavior.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use time.Duration(math.Abs(float64(d))) to ensure non-negative duration before calling Reset()",
      "success_rate": 0.95,
      "how": "Use time.Duration(math.Abs(float64(d))) to ensure non-negative duration before calling Reset()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check duration with if d < 0 { d = 0 } before timer.Reset(d)",
      "success_rate": 0.9,
      "how": "Check duration with if d < 0 { d = 0 } before timer.Reset(d)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use time.NewTimer() with a positive duration and stop it explicitly instead of resetting",
      "success_rate": 0.85,
      "how": "Use time.NewTimer() with a positive duration and stop it explicitly instead of resetting",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use time.Duration(math.Abs(float64(d))) to ensure non-negative duration before calling Reset()",
    "Check duration with if d < 0 { d = 0 } before timer.Reset(d)",
    "Use time.NewTimer() with a positive duration and stop it explicitly instead of resetting"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/time#Timer.Reset",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}