nats-io/nats-server · error

processLeafHeaderMsgArgs Bad or Missing Header Size: '%s'

Error message

processLeafHeaderMsgArgs Bad or Missing Header Size: '%s'

What it means

Leaf-node protocol parse guard: parseSize returned a negative value for the header-size token (missing, non-numeric, or int64 overflow), which the comment in client.go attributes to a malformed or oversized header size field.

Source

Thrown at server/leafnode.go:3211

			return fmt.Errorf("processLeafHeaderMsgArgs Bad or Missing Reply Indicator: '%s'", args[1])
		}
		// Grab header size.
		c.pa.hdb = args[len(args)-2]
		c.pa.hdr = parseSize(c.pa.hdb)

		// Grab size.
		c.pa.szb = args[len(args)-1]
		c.pa.size = parseSize(c.pa.szb)

		// Grab queue names.
		if c.pa.reply != nil {
			c.pa.queues = args[3 : len(args)-2]
		} else {
			c.pa.queues = args[2 : len(args)-2]
		}
	}
	if c.pa.hdr < 0 {
		return fmt.Errorf("processLeafHeaderMsgArgs Bad or Missing Header Size: '%s'", arg)
	}
	if c.pa.size < 0 {
		return fmt.Errorf("processLeafHeaderMsgArgs Bad or Missing Size: '%s'", args)
	}
	if c.pa.hdr > c.pa.size {
		return fmt.Errorf("processLeafHeaderMsgArgs Header Size larger then TotalSize: '%s'", arg)
	}
	maxPayload := atomic.LoadInt32(&c.mpay)
	if maxPayload != jwt.NoLimit && int64(c.pa.size) > int64(maxPayload) {
		c.maxPayloadViolation(c.pa.size, maxPayload)
		return ErrMaxPayload
	}

	// Common ones processed after check for arg length
	c.pa.subject = args[0]

	return nil
}

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Verify the sender encodes the header size correctly
  2. Check for integer overflow in oversized messages
  3. Inspect the raw protocol line for corruption
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/leafnode.go:3211 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/51e7d99323108bea. Report an issue: GitHub.