{"record":{"id":"63ac05e7745bb8b5","repo":"nsqio/nsq","slug":"max-deflate-level-must-be-1-9","errorCode":null,"errorMessage":"--max-deflate-level must be [1,9]","messagePattern":"--max-deflate-level must be \\[1,9\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nsqd/nsqd.go","lineNumber":112,"sourceCode":"\t\toptsNotificationChan: make(chan struct{}, 1),\n\t\tdl:                   dirlock.New(dataPath),\n\t}\n\tn.ctx, n.ctxCancel = context.WithCancel(context.Background())\n\thttpcli := http_api.NewClient(nil, opts.HTTPClientConnectTimeout, opts.HTTPClientRequestTimeout)\n\tn.ci = clusterinfo.New(n.logf, httpcli)\n\n\tn.lookupPeers.Store([]*lookupPeer{})\n\n\tn.swapOpts(opts)\n\tn.errValue.Store(errStore{})\n\n\terr = n.dl.Lock()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to lock data-path: %v\", err)\n\t}\n\n\tif opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 {\n\t\treturn nil, errors.New(\"--max-deflate-level must be [1,9]\")\n\t}\n\n\tif opts.ID < 0 || opts.ID >= 1024 {\n\t\treturn nil, errors.New(\"--node-id must be [0,1024)\")\n\t}\n\n\tif opts.TLSClientAuthPolicy != \"\" && opts.TLSRequired == TLSNotRequired {\n\t\topts.TLSRequired = TLSRequired\n\t}\n\n\ttlsConfig, err := buildTLSConfig(opts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build TLS config - %s\", err)\n\t}\n\tif tlsConfig == nil && opts.TLSRequired != TLSNotRequired {\n\t\treturn nil, errors.New(\"cannot require TLS client connections without TLS key and cert\")\n\t}\n\tn.tlsConfig = tlsConfig","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/nsqio/nsq/blob/85cf10c09c6c3c86160d6f0eb156f62d0efc1648/nsqd/nsqd.go#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set a level in [1,9], e.g. --max-deflate-level=6 (default) or 9 for best compression.","If you meant 'disable deflate', remove --max-deflate-level entirely and do not enable deflate in client IDENTIFY - there is no 0 value.","Check config templating that computes the level (clamp with min/max before rendering)."],"exampleFix":"# before\nnsqd --max-deflate-level=0\n# after\nnsqd --max-deflate-level=6","handlingStrategy":"validation","validationCode":"if opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 {\n\treturn fmt.Errorf(\"invalid max-deflate-level %d: must be in [1,9]\", opts.MaxDeflateLevel)\n}\n_, err := nsqd.New(opts)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp generated config: level = max(1, min(9, level)) before rendering nsqd flags.","Remember 0 is not 'none' - to disable deflate just never enable it in client IDENTIFY."],"tags":["nsq","nsqd","cli","config","compression"],"backgroundTag":null,"analyzedSha":"85cf10c09c6c3c86160d6f0eb156f62d0efc1648","analyzedAt":"2026-08-16T00:53:05.009Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}