{"record":{"id":"8a35782152b86a0b","repo":"nats-io/nats-server","slug":"compression-mode-q-requires-at-least-one-rtt-thre","errorCode":null,"errorMessage":"compression mode %q requires at least one RTT threshold","messagePattern":"compression mode %q requires at least one RTT threshold","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/server.go","lineNumber":543,"sourceCode":"\t\t\t\t// Trim 0 that are at the end.\n\t\t\t\tstop := -1\n\t\t\t\tfor i := len(rtts) - 1; i >= 0; i-- {\n\t\t\t\t\tif rtts[i] != 0 {\n\t\t\t\t\t\tstop = i\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trtts = rtts[:stop+1]\n\t\t\t}\n\t\t\tif len(rtts) > 4 {\n\t\t\t\t// There should be at most values for \"uncompressed\", \"fast\",\n\t\t\t\t// \"better\" and \"best\" (when some 0 are present).\n\t\t\t\treturn fmt.Errorf(\"compression mode %q should have no more than 4 RTT thresholds: %v\", c.Mode, c.RTTThresholds)\n\t\t\t} else if len(rtts) == 0 {\n\t\t\t\t// But there should be at least 1 if the user provided the slice.\n\t\t\t\t// We would be here only if it was provided by say with values\n\t\t\t\t// being a single or all zeros.\n\t\t\t\treturn fmt.Errorf(\"compression mode %q requires at least one RTT threshold\", c.Mode)\n\t\t\t}\n\t\t}\n\t\tc.Mode = CompressionS2Auto\n\t\tc.RTTThresholds = rtts\n\tcase \"fast\", \"s2_fast\":\n\t\tc.Mode = CompressionS2Fast\n\tcase \"better\", \"s2_better\":\n\t\tc.Mode = CompressionS2Better\n\tcase \"best\", \"s2_best\":\n\t\tc.Mode = CompressionS2Best\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported compression mode %q\", c.Mode)\n\t}\n\treturn nil\n}\n\n// Returns `true` if the compression mode `m` indicates that the server\n// will negotiate compression with the remote server, `false` otherwise.","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/server.go#L525-L561","documentation":"validateAndNormalizeCompressionOption: for compression mode 'auto', after trailing zeros are trimmed from rtt_thresholds the slice is empty, so there is no threshold to switch compression on. This happens when the user supplied the slice but it contains only zeros (or normalizes to empty); 'auto' requires at least one meaningful RTT threshold.","triggerScenarios":"Thrown at server/server.go:543 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide at least one non-zero rtt_thresholds entry, e.g. rtt_thresholds: [200ms]","Use fewer than 4 values corresponding to uncompressed/fast/better/best tiers","Omit rtt_thresholds entirely to use defaults instead of supplying all zeros"],"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-08T15:18:49.778Z"}