nats-io/nats-server · error

compression mode %q requires at least one RTT threshold

Error message

compression mode %q requires at least one RTT threshold

What it means

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.

Source

Thrown at server/server.go:543

				// Trim 0 that are at the end.
				stop := -1
				for i := len(rtts) - 1; i >= 0; i-- {
					if rtts[i] != 0 {
						stop = i
						break
					}
				}
				rtts = rtts[:stop+1]
			}
			if len(rtts) > 4 {
				// There should be at most values for "uncompressed", "fast",
				// "better" and "best" (when some 0 are present).
				return fmt.Errorf("compression mode %q should have no more than 4 RTT thresholds: %v", c.Mode, c.RTTThresholds)
			} else if len(rtts) == 0 {
				// But there should be at least 1 if the user provided the slice.
				// We would be here only if it was provided by say with values
				// being a single or all zeros.
				return fmt.Errorf("compression mode %q requires at least one RTT threshold", c.Mode)
			}
		}
		c.Mode = CompressionS2Auto
		c.RTTThresholds = rtts
	case "fast", "s2_fast":
		c.Mode = CompressionS2Fast
	case "better", "s2_better":
		c.Mode = CompressionS2Better
	case "best", "s2_best":
		c.Mode = CompressionS2Best
	default:
		return fmt.Errorf("unsupported compression mode %q", c.Mode)
	}
	return nil
}

// Returns `true` if the compression mode `m` indicates that the server
// will negotiate compression with the remote server, `false` otherwise.

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Provide at least one non-zero rtt_thresholds entry, e.g. rtt_thresholds: [200ms]
  2. Use fewer than 4 values corresponding to uncompressed/fast/better/best tiers
  3. Omit rtt_thresholds entirely to use defaults instead of supplying all zeros
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/server.go:543 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/8a35782152b86a0b. Report an issue: GitHub.