{
  "id": "go/http-server-shutdown-timeout",
  "signature": "http: Server closed",
  "signature_zh": "http：服务器已关闭",
  "regex": "http:\\ Server\\ closed",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Server.Shutdown() is called without a proper context timeout, or the server is closed while active requests are still running, causing the server to return 'http: Server closed' error.",
  "root_cause_type": "generic",
  "root_cause_zh": "调用Server.Shutdown()时未设置正确的上下文超时，或服务器在活动请求仍在运行时被关闭，导致服务器返回'http: Server closed'错误。",
  "versions": [
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Without a timeout, Shutdown() blocks indefinitely, and the server may never close, causing resource leaks.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "os.Exit() bypasses deferred functions and prevents proper server shutdown, leading to incomplete cleanup.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\nif err := srv.Shutdown(ctx); err != nil {\n    log.Fatal(\"Server forced to shutdown:\", err)\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "srv.RegisterOnShutdown(func() {\n    // clean up resources\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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}