{"record":{"id":"de24a08696e2876f","repo":"shadow1ng/fscan","slug":"unexpected-query-opcode-d","errorCode":null,"errorMessage":"unexpected query opcode: %d","messagePattern":"unexpected query opcode: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/services/cassandra.go","lineNumber":220,"sourceCode":"\tif bodyLen == 0 {\n\t\treturn opcode, []byte{}, nil\n\t}\n\tif bodyLen > maxCQLFrameBody {\n\t\treturn opcode, nil, fmt.Errorf(\"cassandra frame too large: %d\", bodyLen)\n\t}\n\tbody := make([]byte, bodyLen)\n\tif _, err := io.ReadFull(conn, body); err != nil {\n\t\treturn opcode, nil, err\n\t}\n\treturn opcode, body, nil\n}\n\nfunc validateCQLQueryResponse(opcode byte, body []byte) error {\n\tif opcode == cqlOpError {\n\t\treturn fmt.Errorf(\"cassandra query failed: %s\", string(body))\n\t}\n\tif opcode != cqlOpResult {\n\t\treturn fmt.Errorf(\"unexpected query opcode: %d\", opcode)\n\t}\n\treturn nil\n}\n\n// cqlStringMap CQL string map 编码: [2B count] [pairs: [2B len] [str]]\nfunc cqlStringMap(m map[string]string) []byte {\n\tvar buf []byte\n\tbuf = append(buf, 0x00, byte(len(m))) // count as short\n\tfor k, v := range m {\n\t\tbuf = append(buf, cqlShortString(k)...)\n\t\tbuf = append(buf, cqlShortString(v)...)\n\t}\n\treturn buf\n}\n\nfunc cqlShortString(s string) []byte {\n\tb := []byte(s)\n\tbuf := make([]byte, 2+len(b))","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/services/cassandra.go#L202-L238","documentation":"Guard in validateCQLQueryResponse: a post-auth QUERY exchange returned an opcode that is neither cqlOpResult nor cqlOpError. It fires when the Cassandra peer violates the expected RESULT/ERROR reply contract, so the query response cannot be validated.","triggerScenarios":"validateCQLQueryResponse is called with an opcode that is neither cqlOpError nor cqlOpResult — e.g. the connection returned an AUTHENTICATE or SUPPORTS frame, or framing desynced so the opcode byte is garbage.","commonSituations":"Talking to an intermediary or non-Cassandra server mid-stream; protocol-version mismatch corrupting frame boundaries; reading a stale response left over from the auth phase.","solutions":["Log the opcode value and compare against the CQL native protocol opcode table to identify the mismatch.","Ensure the auth-phase frames were fully consumed before sending the test query (no leftover bytes in the stream).","Pin a supported protocol version and reconnect to resynchronize framing."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := validateCQLQueryResponse(opcode, body); err != nil && strings.HasPrefix(err.Error(), \"unexpected query opcode\") {\n    return reconnectAndRetry() // framing may be desynced\n}","preventionTips":["Fully consume auth-phase frames before issuing the test query.","Pin a supported protocol version to keep frame boundaries aligned.","Verify no intermediary proxy is mangling the CQL stream."],"tags":["cassandra","cql","protocol","opcode"],"backgroundTag":"unexpected-response-shape","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}