nats-io/nats-server · error
error reading %s: %v
Error message
error reading %s: %v
What it means
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.
Source
Thrown at server/mqtt.go:6350
if l := len(r.pbuf); l > 0 {
tmp := make([]byte, l+len(buf))
copy(tmp, r.pbuf)
copy(tmp[l:], buf)
buf = tmp
r.pbuf = nil
}
r.buf = buf
r.pos = 0
r.pstart = 0
}
func (r *mqttReader) hasMore() bool {
return r.pos != len(r.buf)
}
func (r *mqttReader) readByte(field string) (byte, error) {
if r.pos == len(r.buf) {
return 0, fmt.Errorf("error reading %s: %v", field, io.EOF)
}
b := r.buf[r.pos]
r.pos++
return b, nil
}
func (r *mqttReader) readPacketLen(maxLen int32) (int, bool, error) {
v, complete, err := r.readVarInt()
if err != nil {
return 0, false, err
}
if complete {
packetEnd := r.pos + v
packetLen := packetEnd - r.pstart
if maxLen != jwt.NoLimit && int64(packetLen) > int64(maxLen) {
return packetLen, false, ErrMaxPayload
}
if packetEnd <= len(r.buf) {View on GitHub (pinned to 3a66a489d2)
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
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at server/mqtt.go:6350 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/d139cb737b1c2901.
Report an issue: GitHub.