{"record":{"id":"d22658c3d6a39a44","repo":"vectordotdev/vector","slug":"unable-to-decode-message-len-as-number","errorCode":null,"errorMessage":"Unable to decode message len as number","messagePattern":"Unable to decode message len as number","errorType":"exception","errorClass":"LinesCodecError","httpStatus":null,"severity":"error","filePath":"lib/codecs/src/decoding/framing/octet_counting.rs","lineNumber":150,"sourceCode":"            (State::NotDiscarding, _, Some(space_pos)) if space_pos < self.other.max_length() => {\n                // Everything looks good.\n                //\n                // We aren't discarding, we have a space that is not beyond our\n                // maximum length. Attempt to parse the bytes as a number which\n                // will hopefully give us a sensible length for our message.\n                let len: usize = match std::str::from_utf8(&src[..space_pos])\n                    .map_err(|_| ())\n                    .and_then(|num| num.parse().map_err(|_| ()))\n                {\n                    Ok(len) => len,\n                    Err(_) => {\n                        // It was not a sensible number.\n                        //\n                        // Advance the buffer past the erroneous bytes to\n                        // prevent us getting stuck in an infinite loop.\n                        src.advance(space_pos + 1);\n                        self.octet_decoding = None;\n                        return Err(LinesCodecError::Io(io::Error::new(\n                            io::ErrorKind::InvalidData,\n                            \"Unable to decode message len as number\",\n                        )));\n                    }\n                };\n\n                let from = space_pos + 1;\n                let to = from + len;\n\n                if len > self.other.max_length() {\n                    // The length is greater than we want.\n                    //\n                    // We need to discard the entire message.\n                    self.octet_decoding = Some(State::Discarding(len));\n                    src.advance(space_pos + 1);\n\n                    Ok(None)\n                } else if let Some(msg) = src.get(from..to) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/codecs/src/decoding/framing/octet_counting.rs#L132-L168","documentation":"The octet counting framer reads a leading decimal length prefix followed by a space. This error is raised when the bytes before the first space cannot be parsed as a valid number (the length prefix is not a sensible integer), so the framer cannot determine the message length. The parser advances past the bad bytes to avoid an infinite loop.","triggerScenarios":"Sending data over a TCP stream whose first token is not a decimal length followed by a space; a sender using a different framing protocol (e.g. newline-delimited or syslog) pointed at an octet-counting configured source; corrupted/partial data at the start of the stream.","commonSituations":"Mixing up framing configs between producers and consumers (producer sends plain lines, consumer expects <len> SP <message>); binary or garbage data hitting the port; a load balancer injecting non-protocol data.","solutions":["Fix the sender to emit the octet-counting format: ASCII decimal byte count, one space, then the payload.","Change the Vector source's framing to match the actual sender format (e.g. newline_delimited).","Inspect what is actually arriving on the socket (tcpdump/tcpreceive) to identify the mismatch."],"exampleFix":"// before (sender)\n\"hello world\\n\"\n// after (octet counting)\n\"11 hello world\"","handlingStrategy":"validation","validationCode":"// verify sender emits octet counting format before shipping\nfn looks_like_octet_frame(buf: &[u8]) -> bool {\n    match buf.iter().position(|&b| b == b' ') {\n        Some(sp) => buf[..sp].iter().all(|b| b.is_ascii_digit()),\n        None => false,\n    }\n}","typeGuard":null,"tryCatchPattern":"match framed_stream.next().await {\n    Err(e) if e.kind() == ErrorKind::InvalidData => {\n        // wrong framing: log a sample of raw bytes and reconfigure\n    }\n    other => other?,\n}","preventionTips":["Match producer framing to consumer framing config explicitly.","Send a known test frame (<len> SP <payload>) during deploy validation.","Never point plain-line senders at octet-counting consumers."],"tags":["codecs","framing","tcp","octet-counting"],"backgroundTag":"invalid-message-framing","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}