{"record":{"id":"d139cb737b1c2901","repo":"nats-io/nats-server","slug":"error-reading-s-v","errorCode":null,"errorMessage":"error reading %s: %v","messagePattern":"error reading (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mqtt.go","lineNumber":6350,"sourceCode":"\tif l := len(r.pbuf); l > 0 {\n\t\ttmp := make([]byte, l+len(buf))\n\t\tcopy(tmp, r.pbuf)\n\t\tcopy(tmp[l:], buf)\n\t\tbuf = tmp\n\t\tr.pbuf = nil\n\t}\n\tr.buf = buf\n\tr.pos = 0\n\tr.pstart = 0\n}\n\nfunc (r *mqttReader) hasMore() bool {\n\treturn r.pos != len(r.buf)\n}\n\nfunc (r *mqttReader) readByte(field string) (byte, error) {\n\tif r.pos == len(r.buf) {\n\t\treturn 0, fmt.Errorf(\"error reading %s: %v\", field, io.EOF)\n\t}\n\tb := r.buf[r.pos]\n\tr.pos++\n\treturn b, nil\n}\n\nfunc (r *mqttReader) readPacketLen(maxLen int32) (int, bool, error) {\n\tv, complete, err := r.readVarInt()\n\tif err != nil {\n\t\treturn 0, false, err\n\t}\n\tif complete {\n\t\tpacketEnd := r.pos + v\n\t\tpacketLen := packetEnd - r.pstart\n\t\tif maxLen != jwt.NoLimit && int64(packetLen) > int64(maxLen) {\n\t\t\treturn packetLen, false, ErrMaxPayload\n\t\t}\n\t\tif packetEnd <= len(r.buf) {","sourceCodeStart":6332,"sourceCodeEnd":6368,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/mqtt.go#L6332-L6368","documentation":"mqttReader.readByte hits the end of the buffered packet (r.pos == len(r.buf)) while trying to read the named field, reporting io.EOF for that field. Usually means the packet is truncated relative to its declared remaining length, or a fixed-width field is missing.","triggerScenarios":"Thrown at server/mqtt.go:6350 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the client's remaining-length encoding matches the actual payload","Capture the raw packet to see which field is short","Verify no intermediary is truncating frames"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}