{"record":{"id":"ba8ab43e249e6b88","repo":"nats-io/nats-server","slug":"v-for-account-q-session-q","errorCode":null,"errorMessage":"%v for account %q, session %q","messagePattern":"(.+?) for account %q, session %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mqtt.go","lineNumber":4101,"sourceCode":"\n\t// Register this client ID the \"locked\" map for the duration if this function.\n\tasm.sessLocked[cid] = struct{}{}\n\t// And remove it on exit, regardless of error or not.\n\tdefer func() {\n\t\tasm.mu.Lock()\n\t\tdelete(asm.sessLocked, cid)\n\t\tasm.mu.Unlock()\n\t}()\n\n\t// Is the client requesting a clean session or not.\n\tcleanSess := cp.flags&mqttConnFlagCleanSession != 0\n\t// Session present? Assume false, will be set to true only when applicable.\n\tsessp := false\n\t// Do we have an existing session for this client ID\n\tes, exists := asm.sessions[cid]\n\tasm.mu.Unlock()\n\tformatError := func(err error) error {\n\t\treturn fmt.Errorf(\"%v for account %q, session %q\", err, c.acc.GetName(), cid)\n\t}\n\n\t// The session is not in the map, but may be on disk, so try to recover\n\t// or create the stream if not.\n\tif !exists {\n\t\tes, exists, err = asm.createOrRestoreSession(cid, s.getOpts())\n\t\tif err != nil {\n\t\t\tif err == errMQTTSessionCollision {\n\t\t\t\tsendConnAck(mqttConnAckRCIdentifierRejected, false)\n\t\t\t}\n\t\t\treturn formatError(err)\n\t\t}\n\t}\n\tif exists {\n\t\t// Clear the session if client wants a clean session.\n\t\t// Also, Spec [MQTT-3.2.2-1]: don't report session present\n\t\tif cleanSess || es.clean {\n\t\t\t// Spec [MQTT-3.1.2-6]: If CleanSession is set to 1, the Client and","sourceCodeStart":4083,"sourceCodeEnd":4119,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/mqtt.go#L4083-L4119","documentation":"Not a distinct failure itself: formatError is the closure in the MQTT session-setup code that decorates an underlying error with the account and session (client ID) context, producing '<err> for account \"X\", session \"Y\"'. Seeing it means some other session-establishment error occurred and was annotated.","triggerScenarios":"Thrown at server/mqtt.go:4101 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Look at the wrapped/underlying error text before 'for account' to find the real cause","Fix the session error (storage, limits, state) identified by the inner error"],"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"}