{"record":{"id":"17d53c2c832aa478","repo":"apache/cassandra","slug":"unexpected-request-message-s-expecting-response","errorCode":null,"errorMessage":"Unexpected REQUEST message %s, expecting RESPONSE","messagePattern":"Unexpected REQUEST message (.+?), expecting RESPONSE","errorType":"exception","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/Message.java","lineNumber":502,"sourceCode":"\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    }\n\n    private static final Decoder.RequestDecoder REQUEST_DECODER = new Decoder.RequestDecoder();\n    private static final Decoder.ResponseDecoder RESPONSE_DECODER = new Decoder.ResponseDecoder();\n\n    static Decoder<Message.Request> requestDecoder()\n    {\n        return REQUEST_DECODER;\n    }\n\n    static Decoder<Message.Response> responseDecoder()\n    {\n        return RESPONSE_DECODER;","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/Message.java#L484-L520","documentation":"ProtocolException thrown by Message.Decoder's ResponseDecoder when a frame is a REQUEST-direction message on a connection where RESPONSE messages are expected — i.e. the server's own outbound/response decoding path received something shaped like a client request. It guards the symmetry of the protocol: each side must send only its assigned direction. The frame is rejected before processing.","triggerScenarios":"ResponseDecoder.decode receives an Envelope whose header.type.direction != Direction.RESPONSE, typically when a server-side component (e.g. an internode or testing client) decodes an inbound frame containing QUERY, STARTUP, etc. where a response was expected.","commonSituations":"Using the server's internal client classes against a peer that sends requests back, corrupted frames in-flight, or test harnesses wiring decoders on the wrong side of a connection.","solutions":["Ensure the decoding side actually expects responses (use RequestDecoder on the server, ResponseDecoder only on client-side connections).","Fix the peer that is sending REQUEST-direction messages on a response channel.","Reconnect to resynchronize corrupted streams.","Check test/integration harnesses for swapped decoder wiring."],"exampleFix":"// before: client-side pipeline decodes with the wrong decoder\npipeline.addLast(new Message.Decoder.ResponseDecoder()); // server sends us responses, wrong slot\n// after: clients decode responses, requests are only what we send\npipeline.addLast(new Message.Decoder.RequestDecoder()); // as a server receiving requests\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { frame = decoder.decode(ch, envelope); } catch (ProtocolException e) { log.warn(\"Wrong-direction frame from peer: {}\", e.getMessage()); close(ch); }","preventionTips":["Wire RequestDecoder on the server side and ResponseDecoder only where responses are expected","Use one decoder type per connection side","Verify test harnesses use the correct decoder for their role"],"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"}