{"record":{"id":"6beb5594f9d661eb","repo":"AlexxIT/go2rtc","slug":"unsupported-frame-type-d","errorCode":null,"errorMessage":"unsupported frame type: %d","messagePattern":"unsupported frame type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tcp/websocket/client.go","lineNumber":39,"sourceCode":"}\n\nconst finalBit = 0x80\nconst maskBit = 0x80\n\nfunc (w *Client) Read(b []byte) (n int, err error) {\n\tif w.remain == 0 {\n\t\tb2 := make([]byte, 2)\n\t\tif _, err = io.ReadFull(w.conn, b2); err != nil {\n\t\t\treturn 0, err\n\t\t}\n\n\t\tframeType := b2[0] & 0xF\n\t\tw.remain = int(b2[1] & 0x7F)\n\n\t\tswitch frameType {\n\t\tcase BinaryMessage:\n\t\tdefault:\n\t\t\treturn 0, fmt.Errorf(\"unsupported frame type: %d\", frameType)\n\t\t}\n\n\t\tswitch w.remain {\n\t\tcase 126:\n\t\t\tif _, err = io.ReadFull(w.conn, b2); err != nil {\n\t\t\t\treturn 0, err\n\t\t\t}\n\t\t\tw.remain = int(binary.BigEndian.Uint16(b2))\n\t\tcase 127:\n\t\t\tb8 := make([]byte, 8)\n\t\t\tif _, err = io.ReadFull(w.conn, b8); err != nil {\n\t\t\t\treturn 0, err\n\t\t\t}\n\t\t\tw.remain = int(binary.BigEndian.Uint64(b8))\n\t\t}\n\t}\n\n\tif w.remain > len(b) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tcp/websocket/client.go#L21-L57","documentation":"The websocket client reader only accepts binary frames (opcode 0x2). Any other frame type — text (0x1), ping (0x9), pong (0xA), close (0x8), or continuation (0x0) — results in this error and aborts the read. The library is intentionally minimal and assumes the peer sends binary-only messages.","triggerScenarios":"Calling Read on a websocket.Conn when the remote peer sends a text frame, or when a ping/pong/close control frame arrives mid-stream; the frame type is computed as byte&0xF and anything other than BinaryMessage errors.","commonSituations":"Talking to a server that defaults to JSON text frames; proxies/intermediaries injecting ping frames; misconfigured client that upgrades with a text-oriented subprotocol; library version mismatch where the peer protocol changed.","solutions":["Ensure the peer sends binary frames (send Blob/ArrayBuffer in JS; TextMessage→BinaryMessage in Go clients).","If the peer must send text, change this client to also accept TextMessage in the switch (rebuild the library).","Handle control frames (ping/close) by responding before data frames reach this reader, or strip them with an intermediary.","If the server speaks JSON, marshal your structs to bytes and send as binary on both ends."],"exampleFix":"// before\nswitch frameType {\ncase BinaryMessage:\ndefault:\n\treturn 0, fmt.Errorf(\"unsupported frame type: %d\", frameType)\n}\n// after\nswitch frameType {\ncase BinaryMessage, TextMessage:\ncase PingMessage:\n\twritePong(w.conn)\n\treturn 0, nil\ndefault:\n\treturn 0, fmt.Errorf(\"unsupported frame type: %d\", frameType)\n}","handlingStrategy":"try-catch","validationCode":"// Negotiate binary-only subprotocol or verify peer frame usage before streaming\nif !peerSupportsBinaryFrames(serverURL) {\n\treturn errors.New(\"peer sends non-binary frames; unsupported by client\")\n}","typeGuard":"func isBinaryOpcode(b byte) bool { return b&0xF == 0x2 }","tryCatchPattern":"n, err := wsConn.Read(buf)\nif err != nil {\n\tvar frameErr unsupportedFrameError\n\tif errors.As(err, &frameErr) {\n\t\treturn handleNonBinaryFrame(frameErr.FrameType)\n\t}\n\treturn err\n}","preventionTips":["Always send binary frames from the peer (Blob/ArrayBuffer, BinaryMessage)","Handle ping/pong/close frames at a layer below this reader","Agree on binary framing in the protocol before deploying","Audit intermediaries that may inject control frames"],"tags":["websocket","protocol","parsing","network"],"backgroundTag":"unsupported-operation","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}