{"record":{"id":"68441a8c26bed3cc","repo":"nats-io/nats-server","slug":"sort-by-stop-only-valid-on-closed-connections","errorCode":null,"errorMessage":"sort by stop only valid on closed connections","messagePattern":"sort by stop only valid on closed connections","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/monitor.go","lineNumber":252,"sourceCode":"\t\tacc = opts.Account\n\t\tmqttCID = opts.MQTTClient\n\n\t\tsubs = opts.Subscriptions\n\t\tsubsDet = opts.SubscriptionsDetail\n\t\toffset = opts.Offset\n\t\tif offset < 0 {\n\t\t\toffset = 0\n\t\t}\n\t\tlimit = opts.Limit\n\t\tif limit <= 0 {\n\t\t\tlimit = DefaultConnListSize\n\t\t}\n\t\t// state\n\t\tstate = opts.State\n\n\t\t// ByStop only makes sense on closed connections\n\t\tif sortOpt == ByStop && state != ConnClosed {\n\t\t\treturn nil, fmt.Errorf(\"sort by stop only valid on closed connections\")\n\t\t}\n\t\t// ByReason is the same.\n\t\tif sortOpt == ByReason && state != ConnClosed {\n\t\t\treturn nil, fmt.Errorf(\"sort by reason only valid on closed connections\")\n\t\t}\n\t\t// If searching by CID\n\t\tif opts.CID > 0 {\n\t\t\tcid = opts.CID\n\t\t\tlimit = 1\n\t\t}\n\t\t// If filtering by subject.\n\t\tif opts.FilterSubject != _EMPTY_ && opts.FilterSubject != fwcs {\n\t\t\tif acc == _EMPTY_ {\n\t\t\t\treturn nil, fmt.Errorf(\"filter by subject only valid with account filtering\")\n\t\t\t}\n\t\t\tfilter = opts.FilterSubject\n\t\t}\n\t}","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/monitor.go#L234-L270","documentation":"Returned by Connz when the sort option is ByStop but the requested connection state filter is not ConnClosed. Stop timestamps only exist for closed connections, so sorting open connections by stop time is meaningless and rejected.","triggerScenarios":"Thrown at server/monitor.go:252 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add state=closed (or omit state so it defaults appropriately) when sorting by stop","Choose a sort field valid for open connections, such as cid or uptime"],"exampleFix":null,"handlingStrategy":"validation","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"}