{"record":{"id":"69cceeb0bad53626","repo":"apache/cassandra","slug":"unexpected-response-message-s-expecting-request","errorCode":null,"errorMessage":"Unexpected RESPONSE message %s, expecting REQUEST","messagePattern":"Unexpected RESPONSE message (.+?), expecting REQUEST","errorType":"exception","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/Message.java","lineNumber":490,"sourceCode":"            else\n            {\n                assert message instanceof Response;\n                if (isTracing)\n                    ((Response) message).setTracingId(tracingId);\n                if (hasWarning)\n                    ((Response) message).setWarnings(warnings);\n            }\n            return message;\n        }\n\n        abstract M decode(Channel channel, Envelope inbound);\n\n        private static class RequestDecoder extends Decoder<Request>\n        {\n            Request decode(Channel channel, Envelope request)\n            {\n                if (request.header.type.direction != Direction.REQUEST)\n                    throw new ProtocolException(String.format(\"Unexpected RESPONSE message %s, expecting REQUEST\",\n                                                              request.header.type));\n\n                return (Request) decodeMessage(channel, request);\n            }\n        }\n\n        private static class ResponseDecoder extends Decoder<Response>\n        {\n            Response decode(Channel channel, Envelope response)\n            {\n                if (response.header.type.direction != Direction.RESPONSE)\n                    throw new ProtocolException(String.format(\"Unexpected REQUEST message %s, expecting RESPONSE\",\n                                                              response.header.type));\n\n                return (Response) decodeMessage(channel, response);\n            }\n        }\n    }","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/Message.java#L472-L508","documentation":"ProtocolException thrown by Message.Decoder's RequestDecoder when a decoded frame is a RESPONSE-direction message even though the server-side decoder only accepts REQUEST messages. Each connection side has a decoder for the direction it should receive; receiving the opposite direction means the peer is speaking out of turn. The frame is rejected before any handler runs.","triggerScenarios":"RequestDecoder.decode receives an Envelope whose header.type.direction != Direction.REQUEST, i.e. a client sent a message type such as RESULT or ERROR to the server.","commonSituations":"A buggy custom client echoing server responses back, stream corruption from a proxy, fuzzing/malicious traffic on the native port, or wrong-direction opcodes in hand-written clients.","solutions":["Fix the client to only send REQUEST-direction messages over connections to the server.","Reconnect to resynchronize; inspect intermediary proxies for frame corruption.","Block or rate-limit untrusted clients hitting the native port; treat this as a protocol violation from that peer.","Verify driver version compatibility with the server's protocol."],"exampleFix":"// before: custom client writes back the server's RESULT message\nchannel.writeAndFlush(resultMessage); // direction RESPONSE\n// after: only send request messages upstream\nchannel.writeAndFlush(new QueryMessage(cql, ConsistencyLevel.ONE)); // direction REQUEST","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { frame = decodeFrame(buf); } catch (ProtocolException e) { metrics.protocolViolations.inc(); closeChannelQuietly(); }","preventionTips":["Never route response messages back to the server","Reconnect on any protocol error — the stream cannot recover in place","Inspect proxies if these errors appear in bursts"],"tags":["cassandra","native-protocol","network"],"backgroundTag":"unexpected-response-shape","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}