{"record":{"id":"70c7e3a9a3b93afe","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-decompress-response-body-from-s-w","errorCode":null,"errorMessage":"cannot decompress response body from %s: %w","messagePattern":"cannot decompress response body from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/promscrape/scrapework.go","lineNumber":506,"sourceCode":"\tleveledbytebufferpool.Put(body)\n\n\t<-processScrapedDataConcurrencyLimitCh\n\n\treturn err\n}\n\nvar processScrapedDataConcurrencyLimitCh = make(chan struct{}, cgroup.AvailableCPUs())\n\nfunc (sw *scrapeWork) readFromBuffer(dst *bytesutil.ByteBuffer, src *chunkedbuffer.Buffer, isGzipped bool) error {\n\tif !isGzipped {\n\t\tsrc.MustWriteTo(dst)\n\t\treturn nil\n\t}\n\n\tr := src.NewReader()\n\treader, err := protoparserutil.GetUncompressedReader(r, \"gzip\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot decompress response body from %s: %w\", sw.Config.ScrapeURL, err)\n\t}\n\n\tlr := ioutil.GetLimitedReader(reader, sw.Config.MaxScrapeSize+1)\n\t_, err = dst.ReadFrom(lr)\n\tioutil.PutLimitedReader(lr)\n\n\tprotoparserutil.PutUncompressedReader(reader)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot read gzipped response body from %s: %w\", sw.Config.ScrapeURL, err)\n\t}\n\n\tif int64(dst.Len()) > sw.Config.MaxScrapeSize {\n\t\tmaxScrapeSizeExceeded.Inc()\n\t\treturn fmt.Errorf(\"the uncompressed response from %q exceeds -promscrape.maxScrapeSize or max_scrape_size in the scrape config (%d bytes). \"+\n\t\t\t\"Possible solutions are: reduce the response size for the target, increase -promscrape.maxScrapeSize command-line flag, \"+\n\t\t\t\"increase max_scrape_size value in scrape config for the given target\", sw.Config.ScrapeURL, sw.Config.MaxScrapeSize)\n\t}\n\treturn nil","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/promscrape/scrapework.go#L488-L524","documentation":"During a scrape, readFromBuffer decompresses the target's gzip-encoded response body via protoparserutil.GetUncompressedReader. This error means the gzip stream from the scrape target is malformed or truncated and cannot be decompressed; the scrape for that target fails. The scrape URL is included for identification.","triggerScenarios":"A scrape target (through getTargetResponse/scrapeInternal) returns a body advertised as gzip ('Content-Encoding: gzip') that is invalid gzip data, corrupted, or cut off mid-stream.","commonSituations":"Target behind a proxy that re-encodes or corrupts responses; a server that gzips only headers but sends plain body (double-encoding bugs); scraping an endpoint that returns binary/non-gzip data while gzip is requested; network truncation of large responses.","solutions":["Curl the scrape URL with gzip and inspect whether the body is valid gzip (file/gunzip).","Check intermediate proxies/load balancers for response rewriting or compression bugs.","Verify the target does not send conflicting Content-Encoding; fix server compression settings.","Retry if caused by transient network truncation of the response."],"exampleFix":"// before: server sends plain text while client requests gzip\nContent-Encoding: identity\n// after: target must honor gzip negotiation or send valid gzip\nContent-Encoding: gzip (with actual gzip-compressed body)","handlingStrategy":"retry","validationCode":"// verify the target serves valid gzip\ncurl -sH 'Accept-Encoding: gzip' -o /tmp/m.gz $SCRAPE_URL && gunzip -t /tmp/m.gz && echo OK\n","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"cannot decompress response body\") {\n    // re-scrape once; if persistent, inspect proxy/server encoding\n}\n","preventionTips":["Test gzip output of exporters with curl + gunzip -t","Check proxies don't corrupt or double-encode bodies","Avoid scraping non-metrics endpoints by mistake"],"tags":["promscrape","gzip","decompression","scraping"],"backgroundTag":"gzip-decompression-failed","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}