nsqio/nsq · error

--max-deflate-level must be [1,9]

Error message

--max-deflate-level must be [1,9]

What it means

nsqd.New validates opts.MaxDeflateLevel (flag --max-deflate-level, default 6) against the DEFLATE spec: only levels 1..9 exist, so anything outside that range aborts startup. The value caps the compression level a client may negotiate via IDENTIFY's deflate_level when the connection enables deflate.

Source

Thrown at nsqd/nsqd.go:112

		optsNotificationChan: make(chan struct{}, 1),
		dl:                   dirlock.New(dataPath),
	}
	n.ctx, n.ctxCancel = context.WithCancel(context.Background())
	httpcli := http_api.NewClient(nil, opts.HTTPClientConnectTimeout, opts.HTTPClientRequestTimeout)
	n.ci = clusterinfo.New(n.logf, httpcli)

	n.lookupPeers.Store([]*lookupPeer{})

	n.swapOpts(opts)
	n.errValue.Store(errStore{})

	err = n.dl.Lock()
	if err != nil {
		return nil, fmt.Errorf("failed to lock data-path: %v", err)
	}

	if opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 {
		return nil, errors.New("--max-deflate-level must be [1,9]")
	}

	if opts.ID < 0 || opts.ID >= 1024 {
		return nil, errors.New("--node-id must be [0,1024)")
	}

	if opts.TLSClientAuthPolicy != "" && opts.TLSRequired == TLSNotRequired {
		opts.TLSRequired = TLSRequired
	}

	tlsConfig, err := buildTLSConfig(opts)
	if err != nil {
		return nil, fmt.Errorf("failed to build TLS config - %s", err)
	}
	if tlsConfig == nil && opts.TLSRequired != TLSNotRequired {
		return nil, errors.New("cannot require TLS client connections without TLS key and cert")
	}
	n.tlsConfig = tlsConfig

View on GitHub (pinned to 85cf10c09c)

Solutions

  1. Set a level in [1,9], e.g. --max-deflate-level=6 (default) or 9 for best compression.
  2. If you meant 'disable deflate', remove --max-deflate-level entirely and do not enable deflate in client IDENTIFY - there is no 0 value.
  3. Check config templating that computes the level (clamp with min/max before rendering).

Example fix

# before
nsqd --max-deflate-level=0
# after
nsqd --max-deflate-level=6
Defensive patterns

Strategy: validation

Validate before calling

if opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 {
	return fmt.Errorf("invalid max-deflate-level %d: must be in [1,9]", opts.MaxDeflateLevel)
}
_, err := nsqd.New(opts)

Prevention

When it happens

Trigger: Starting nsqd with --max-deflate-level=0, a negative number, or 10+. The check is opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 and runs after the data-path lock is acquired but before any listener starts, so the process exits with this error.

Common situations: Confusing this cap with zlib's 0=none setting (people pass 0 intending 'no preference'); copy-paste from Go's compress/flate docs where BestCompression=9 and HuffmanOnly=-2; config generation math producing out-of-range values.

Related errors


AI-assisted analysis of nsqio/nsq@85cf10c09c (2026-08-16). Data as JSON: /api/errors/63ac05e7745bb8b5. Report an issue: GitHub.