{
  "id": "api/websocket-close-code-1002-protocol-error",
  "signature": "WebSocket close code 1002: Protocol Error",
  "signature_zh": "WebSocket 关闭代码 1002：协议错误",
  "regex": "WebSocket close code 1002: Protocol Error",
  "domain": "api",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "WebSocket frame was malformed or contained invalid data, such as a reserved opcode or fragmented control frame.",
  "root_cause_type": "generic",
  "root_cause_zh": "WebSocket 帧格式错误或包含无效数据，例如保留操作码或分片控制帧。",
  "versions": [
    {
      "version": "RFC 6455",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ws library 8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Socket.IO 4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Spring WebSocket 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Node.js ws 8.14+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The error is immediate and not related to timeouts.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The root cause is in the client's frame construction, not server state.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Validate that control frames (e.g., ping, pong, close) are not fragmented. In JavaScript, ensure you are not sending a fragmented ping frame:\n// Bad: Sending a fragmented ping\nws.send(Buffer.from('ping'), { fin: false, opcode: 0x9 }); // Wrong!\n// Good: Send a complete ping frame\nws.ping(); // Uses correct non-fragmented frame",
      "success_rate": 0.9,
      "how": "Validate that control frames (e.g., ping, pong, close) are not fragmented. In JavaScript, ensure you are not sending a fragmented ping frame:\n// Bad: Sending a fragmented ping\nws.send(Buffer.from('ping'), { fin: false, opcode: 0x9 }); // Wrong!\n// Good: Send a complete ping frame\nws.ping(); // Uses correct non-fragmented frame",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check for reserved opcodes (0x3-0x7, 0xB-0xF) in the frame. If using a custom WebSocket library, ensure opcode is in {0x0, 0x1, 0x2, 0x8, 0x9, 0xA}.",
      "success_rate": 0.85,
      "how": "Check for reserved opcodes (0x3-0x7, 0xB-0xF) in the frame. If using a custom WebSocket library, ensure opcode is in {0x0, 0x1, 0x2, 0x8, 0x9, 0xA}.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Validate that control frames (e.g., ping, pong, close) are not fragmented. In JavaScript, ensure you are not sending a fragmented ping frame:\n// Bad: Sending a fragmented ping\nws.send(Buffer.from('ping'), { fin: false, opcode: 0x9 }); // Wrong!\n// Good: Send a complete ping frame\nws.ping(); // Uses correct non-fragmented frame",
    "Check for reserved opcodes (0x3-0x7, 0xB-0xF) in the frame. If using a custom WebSocket library, ensure opcode is in {0x0, 0x1, 0x2, 0x8, 0x9, 0xA}."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1",
  "official_doc_section": null,
  "error_code": "1002",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-09-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}