nats-io/nats-server · error

processPub Parse Error: %q

Error message

processPub Parse Error: %q

What it means

The PUB protocol operation could not be tokenized correctly. processPub expects 3 args (subject, reply, size) for pub with reply or 2 args (subject, size) for plain pub; any other arg count hits the default branch and returns this parse error, closing the connection.

Source

Thrown at server/client.go:2987

	}
	if start >= 0 {
		args = append(args, arg[start:])
	}

	c.pa.arg = arg
	switch len(args) {
	case 2:
		c.pa.subject = args[0]
		c.pa.reply = nil
		c.pa.size = parseSize(args[1])
		c.pa.szb = args[1]
	case 3:
		c.pa.subject = args[0]
		c.pa.reply = args[1]
		c.pa.size = parseSize(args[2])
		c.pa.szb = args[2]
	default:
		return fmt.Errorf("processPub Parse Error: %q", arg)
	}
	// If number overruns an int64, parseSize() will have returned a negative value
	if c.pa.size < 0 {
		return fmt.Errorf("processPub Bad or Missing Size: %q", arg)
	}
	maxPayload := atomic.LoadInt32(&c.mpay)
	// Use int64() to avoid int32 overrun...
	if maxPayload != jwt.NoLimit && int64(c.pa.size) > int64(maxPayload) {
		c.maxPayloadViolation(c.pa.size, maxPayload)
		return ErrMaxPayload
	}
	if c.opts.Pedantic && !IsValidLiteralSubject(bytesToString(c.pa.subject)) {
		c.sendErr("Invalid Publish Subject")
	}
	return nil
}

func splitArg(arg []byte) [][]byte {

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Emit PUB with exactly `PUB <subject> <size>` or `PUB <subject> <reply> <size>` followed by CRLF and the payload
  2. Fix or upgrade the client library generating the frames
  3. Verify no intermediary proxy/middlebox alters whitespace or line framing

Example fix

// before
PUB subject
// after
PUB subject 5
hello
Defensive patterns

Strategy: validation

Validate before calling

if reply == "" {
    frame = fmt.Sprintf("PUB %s %d\r\n", subject, len(payload))
} else {
    frame = fmt.Sprintf("PUB %s %s %d\r\n", subject, reply, len(payload))
}

Prevention

When it happens

Trigger: Client sends `PUB` with the wrong number of space-separated tokens, e.g. `PUB subject` (missing size) or `PUB subject reply size extra`, so the switch on len(args) falls through to default.

Common situations: Hand-crafted protocol frames in scripts/tests, broken telnet-style clients, a proxy splitting or merging protocol lines, client library bug after a protocol change.

Understand the failure class

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/f0188d15040a12f0. Report an issue: GitHub.