{"record":{"id":"931936219ec1bf49","repo":"nats-io/nats-server","slug":"compression-mode-q-should-have-no-more-than-4-rtt","errorCode":null,"errorMessage":"compression mode %q should have no more than 4 RTT thresholds: %v","messagePattern":"compression mode %q should have no more than 4 RTT thresholds: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/server.go","lineNumber":538,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trtts = append(rtts, n)\n\t\t\t}\n\t\t\tif len(rtts) > 0 {\n\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}","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/server.go#L520-L556","documentation":"A compression mode's RTTThresholds list may contain at most 4 entries, corresponding to 'uncompressed', 'fast', 'better' and 'best' levels (with 0 entries allowed to skip levels). Providing more than 4 thresholds exceeds the defined compression levels, so Options validation rejects the configuration.","triggerScenarios":"Setting Options.RTTThresholds with 5 or more entries for a compression mode, e.g. [10, 20, 30, 40, 50].","commonSituations":"Users extrapolating the threshold list thinking more granularity is supported, config generators producing per-node thresholds, or misunderstanding that zeros only mask levels rather than adding capacity.","solutions":["Trim RTTThresholds to at most 4 non-redundant entries","Map each entry to the documented levels: uncompressed, fast, better, best","Use 0 values to disable intermediate levels rather than adding more thresholds","Validate the config against the server's compression docs before rollout"],"exampleFix":"// before\nc.RTTThresholds = []int64{5, 10, 20, 40, 80} // 5 entries\n// after\nc.RTTThresholds = []int64{10, 20, 40} // <= 4 entries","handlingStrategy":"validation","validationCode":"// Go: cap RTTThresholds length before applying Options\nif n := countNonZero(cfg.RTTThresholds); n > 4 {\n    return fmt.Errorf(\"at most 4 RTT thresholds allowed, got %d\", n)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Design threshold configs around the 4 defined compression levels","Use 0 to disable a level instead of adding extra thresholds","Validate compression config against docs before deploy"],"tags":["nats-server","configuration","compression","options-validation"],"backgroundTag":"invalid-config-option","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}