{"record":{"id":"9274d37b13ec3195","repo":"nats-io/nats-server","slug":"processunsub-parse-error-q","errorCode":null,"errorMessage":"processUnsub Parse Error: %q","messagePattern":"processUnsub Parse Error: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/client.go","lineNumber":3527,"sourceCode":"\t// We can skip subscriptions on reserved replies.\n\tif acc != nil && !isReservedReply(sub.subject) {\n\t\tacc.checkForReverseEntry(string(sub.subject), nil, true)\n\t}\n}\n\nfunc (c *client) processUnsub(arg []byte) error {\n\targs := splitArg(arg)\n\tvar sid []byte\n\tmax := int64(-1)\n\n\tswitch len(args) {\n\tcase 1:\n\t\tsid = args[0]\n\tcase 2:\n\t\tsid = args[0]\n\t\tmax = int64(parseSize(args[1]))\n\tdefault:\n\t\treturn fmt.Errorf(\"processUnsub Parse Error: %q\", arg)\n\t}\n\n\tvar sub *subscription\n\tvar ok, unsub bool\n\n\tc.mu.Lock()\n\n\t// Indicate activity.\n\tc.in.subs++\n\n\t// Grab connection type.\n\tkind := c.kind\n\tsrv := c.srv\n\tvar acc *Account\n\n\tupdateGWs := false\n\tif sub, ok = c.subs[string(sid)]; ok {\n\t\tacc = c.acc","sourceCodeStart":3509,"sourceCodeEnd":3545,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/client.go#L3509-L3545","documentation":"The UNSUB protocol operation had an invalid argument count. processUnsub expects 1 arg (sid) or 2 args (sid, max-messages); any other count returns this parse error and the connection is treated as a protocol violator.","triggerScenarios":"Client sends `UNSUB` with 0 or 3+ tokens, e.g. bare `UNSUB`, or `UNSUB sid max extra`, so the switch on len(args) falls to default.","commonSituations":"Custom or scripted clients appending extra tokens, max-message limit logic emitting a malformed second arg, proxy interference with line framing.","solutions":["Send `UNSUB <sid>` or `UNSUB <sid> <maxMsgs>` followed by CRLF, exactly 1 or 2 args","Fix the client code that formats the UNSUB frame, ensuring the optional max is a valid integer token","Use server debug logs to see the offending line"],"exampleFix":"// before\nUNSUB 1 10 extra\n// after\nUNSUB 1 10","handlingStrategy":"validation","validationCode":"if maxMsgs > 0 {\n    frame = fmt.Sprintf(\"UNSUB %s %d\\r\\n\", sid, maxMsgs)\n} else {\n    frame = fmt.Sprintf(\"UNSUB %s\\r\\n\", sid)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Send exactly one token (sid) or two (sid, max)","Only include max when the auto-unsubscribe limit is actually desired","Use the official client's Unsubscribe/AutoUnsubscribe APIs"],"tags":["protocol","parsing","subscription"],"backgroundTag":"nats-protocol-parse-error","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}