{"record":{"id":"1aa99bb7954aa0cf","repo":"tracel-ai/burn","slug":"can-deserialize-messages-from-the-websocket","errorCode":null,"errorMessage":"Can deserialize messages from the websocket.","messagePattern":"Can deserialize messages from the websocket\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-communication/src/external_comm.rs","lineNumber":167,"sourceCode":"\n        // Send the download request with the download id\n        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 => {","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-communication/src/external_comm.rs#L149-L185","documentation":"This panic occurs in download_tensor when deserializing a websocket message with rmp_serde (MessagePack) into ExternalCommMessage fails, or when the deserialized message is not the Tensor variant. It indicates protocol desynchronization: the peer sent bytes that are not a valid tensor response — a different burn/protocol version, corrupt frame, or a foreign message type on this connection.","triggerScenarios":"Receiving a message from a peer running a different burn-communication version with a changed ExternalCommMessage enum; the data channel delivering interleaved/misrouted frames; truncated or corrupted MessagePack payloads on a flaky connection.","commonSituations":"Mixed-version cluster where nodes were upgraded independently; middleware/proxy mangling binary frames; two servers sharing a websocket channel with mismatched message expectations.","solutions":["Ensure all peers run the same burn/burn-communication version so ExternalCommMessage encodes identically.","Log and return None (treat as failed download) instead of panicking on unexpected message types.","Inspect the raw bytes of the failing frame to confirm whether it is corrupt or a different message variant.","Check for proxies/middleware that could alter binary websocket frames (disable permessage-deflate mismatches, ensure binary framing)."],"exampleFix":"// before\nlet ExternalCommMessage::Tensor(data) = rmp_serde::from_slice(&msg.data)\n    .expect(\"Can deserialize messages from the websocket.\")\nelse { panic!(\"Message should have been TensorData\") };\n// after\nmatch rmp_serde::from_slice::<ExternalCommMessage>(&msg.data) {\n    Ok(ExternalCommMessage::Tensor(data)) => return Some(data),\n    Ok(other) => log::warn!(\"unexpected message {other:?}\"),\n    Err(e) => log::warn!(\"deserialization failed: {e}\"),\n}\nreturn None;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn as_tensor_msg(bytes: &[u8]) -> Option<ExternalCommMessage> {\n    match rmp_serde::from_slice::<ExternalCommMessage>(bytes) {\n        Ok(ExternalCommMessage::Tensor(d)) => Some(ExternalCommMessage::Tensor(d)),\n        _ => None,\n    }\n}","tryCatchPattern":"let Some(ExternalCommMessage::Tensor(data)) = as_tensor_msg(&msg.data) else {\n    log::warn!(\"non-tensor/corrupt frame received\");\n    return None;\n};","preventionTips":["Pin identical burn versions across all communicating nodes.","Verify transports preserve binary websocket frames (no lossy proxies).","Negotiate a protocol version in the handshake."],"tags":["websocket","serialization","messagepack","protocol"],"backgroundTag":"message-deserialization-failed","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"}