{"record":{"id":"55d81c9131719a39","repo":"tracel-ai/burn","slug":"message-should-have-been-tensordata","errorCode":null,"errorMessage":"Message should have been TensorData","messagePattern":"Message should have been TensorData","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-communication/src/external_comm.rs","lineNumber":169,"sourceCode":"        let bytes: bytes::Bytes =\n            rmp_serde::to_vec(&ExternalCommMessage::TensorRequest(transfer_id))\n                .unwrap()\n                .into();\n        stream\n            .send(Message::new(bytes))\n            .await\n            .expect(\"Failed to send download id\");\n\n        if let Ok(msg) = stream.recv().await {\n            let Some(msg) = msg else {\n                log::warn!(\"Received None message from the websocket, closing connection.\");\n                return None;\n            };\n\n            let ExternalCommMessage::Tensor(data) = rmp_serde::from_slice(&msg.data)\n                .expect(\"Can deserialize messages from the websocket.\")\n            else {\n                panic!(\"Message should have been TensorData\")\n            };\n            return Some(data);\n        }\n        log::warn!(\"Closed connection\");\n        None\n    }\n\n    /// Get the WebSocket stream for the given address, or create a new one if it doesn't exist.\n    async fn get_data_stream(\n        &self,\n        address: Address,\n    ) -> Arc<Mutex<<P::Client as ProtocolClient>::Channel>> {\n        let mut streams = self.channels.lock().await;\n        match streams.get(&address) {\n            Some(stream) => stream.clone(),\n            None => {\n                // Open a new WebSocket connection to the address\n                let stream = match P::Client::connect(address.clone(), \"data\").await {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-communication/src/external_comm.rs#L151-L187","documentation":"When downloading a tensor over the remote WebSocket 'data' channel, the client expects every message to deserialize as `ExternalCommMessage::Tensor`. If deserialization succeeds but the variant differs, this panic fires — the peer sent an unexpected message type on the data channel, indicating a protocol mismatch between client and server.","triggerScenarios":"A burn-remote server (or proxy) responding on the 'data' channel with a non-Tensor message (e.g. TensorRequest, error, or a message from a different burn version); connecting a client to a server running incompatible burn-communication protocol.","commonSituations":"Version skew between client and server burn crates; a misconfigured intermediary that forwards control-channel messages onto the data channel; two peers both acting as downloaders and answering each other's TensorRequests.","solutions":["Ensure client and server use compatible versions of burn-communication/burn-remote so message enums match.","Verify the server actually streams TensorData on the 'data' subprotocol channel, not control messages.","Capture the debug output in the panic message ({msg:?}) to identify the unexpected variant and fix the peer."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// On the client side, validate the variant instead of panicking\nif let ExternalCommMessage::Tensor(data) = msg { /* use data */ } else { log::warn!(\"unexpected data-channel message\"); }","typeGuard":"fn as_tensor(msg: ExternalCommMessage) -> Option<TensorData> {\n    match msg { ExternalCommMessage::Tensor(d) => Some(d), _ => None }\n}","tryCatchPattern":"// Wrap download in a task and convert panic to error\nlet res = tokio::spawn(async move { download(...).await }).await;\nmatch res { Ok(Ok(data)) => data, _ => Err(ProtocolMismatch) }","preventionTips":["Pin matching burn versions on client and server","Only send TensorData on the 'data' channel","Log and handle unexpected variants instead of assuming"],"tags":["rust","burn","websocket","protocol"],"backgroundTag":"unexpected-message-type","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}