{"record":{"id":"7b6f15dd3bc42a7c","repo":"nginx/nginx","slug":"ngx-log-alert-7b6f15","errorCode":"NGX_LOG_ALERT","errorMessage":"inflateInit2() failed: %d","messagePattern":"inflateInit2\\(\\) failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/http/modules/ngx_http_gunzip_filter_module.c","lineNumber":318,"sourceCode":"\nstatic ngx_int_t\nngx_http_gunzip_filter_inflate_start(ngx_http_request_t *r,\n    ngx_http_gunzip_ctx_t *ctx)\n{\n    int  rc;\n\n    ctx->zstream.next_in = NULL;\n    ctx->zstream.avail_in = 0;\n\n    ctx->zstream.zalloc = ngx_http_gunzip_filter_alloc;\n    ctx->zstream.zfree = ngx_http_gunzip_filter_free;\n    ctx->zstream.opaque = ctx;\n\n    /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */\n    rc = inflateInit2(&ctx->zstream, MAX_WBITS + 16);\n\n    if (rc != Z_OK) {\n        ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n                      \"inflateInit2() failed: %d\", rc);\n        return NGX_ERROR;\n    }\n\n    ctx->started = 1;\n\n    ctx->last_out = &ctx->out;\n    ctx->flush = Z_NO_FLUSH;\n\n    return NGX_OK;\n}\n\n\nstatic ngx_int_t\nngx_http_gunzip_filter_add_data(ngx_http_request_t *r,\n    ngx_http_gunzip_ctx_t *ctx)\n{\n    ngx_chain_t  *cl;","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/nginx/nginx/blob/3f6f7824d4e2eb1ac37dec76683d525ac0ff521c/src/http/modules/ngx_http_gunzip_filter_module.c#L300-L336","documentation":"The gunzip filter failed to initialize zlib for decoding a gzip-encoded response: inflateInit2(MAX_WBITS + 16) returned something other than Z_OK. zlib only fails init with Z_MEM_ERROR (or Z_STREAM_ERROR for invalid args, which cannot occur here since windowBits is fixed at 47 for gzip), so this is effectively an out-of-memory condition logged at ALERT.","triggerScenarios":"First gzip buffer of a response arrives (Content-Encoding: gzip, client without gzip support, gunzip on) and zlib's inflateInit2 cannot allocate its internal window/state due to process memory exhaustion.","commonSituations":"nginx under memory pressure (cgroup limits, rlimits, or memory leaks elsewhere), very high concurrency inflating many large streams at once; typically transient.","solutions":["Check nginx memory usage and limits at the time of the alert (dmesg for OOM kills, container/cgroup limits)","Reduce concurrent gunzip work: lower worker_connections or gzip_buffers pressure, or stop the upstream from gzipping payloads nginx must decompress for non-gzip clients","If recurrent without memory pressure, suspect a broken zlib build and rebuild against stock zlib"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# no config-level pre-check exists; watch the leading indicators instead:\n# worker RSS and cgroup memory pressure\nfor p in $(pgrep -f 'nginx: worker'); do awk '/VmRSS/ {print $2}' /proc/$p/status; done","typeGuard":null,"tryCatchPattern":"Let nginx retry at the request level (clients see one failed response); fix the memory condition rather than catching — the next request retries inflateInit2 naturally.","preventionTips":["Cap concurrent decompressions by limiting worker_connections and avoiding gunzip on huge streams","Size gzip_buffers/gunzip_buffers to your traffic instead of copying extreme values"],"tags":["nginx","gunzip","zlib","memory","response-filter"],"backgroundTag":"zlib-initialization-failed","analyzedSha":"3f6f7824d4e2eb1ac37dec76683d525ac0ff521c","analyzedAt":"2026-08-22T03:09:46.447Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}