Compare commits

...

2 Commits

Author SHA1 Message Date
Nikolay
c08e589274 Update CHANGELOG.md
Signed-off-by: Nikolay <nik@victoriametrics.com>
2026-08-18 10:54:16 +02:00
f41gh7
9c435739cd lib/promscrape: properly re-use buffer at http request
Previously, it may cause data-race if scrape request failed on error.
Because background goroutine at http client could read data
concurrently from buffer after error return.

See https://github.com/VictoriaMetrics/VictoriaLogs/pull/1616
2026-08-18 10:26:20 +02:00
2 changed files with 6 additions and 2 deletions

View File

@@ -26,6 +26,8 @@ See also [LTS releases](https://docs.victoriametrics.com/victoriametrics/lts-rel
## tip
* BUGFIX: [vmagent](https://docs.victoriametrics.com/victoriametrics/vmagent/) and [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/): prevent rare data-race during during target scape. See [#11419](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/11419).
## [v1.150.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.150.0)
Released at 2026-08-17

View File

@@ -429,12 +429,14 @@ func (sw *scrapeWork) needStreamParseMode(responseSize int) bool {
// getTargetResponse() fetches response from sw target in the same way as when scraping the target.
func (sw *scrapeWork) getTargetResponse() ([]byte, error) {
cb := chunkedbuffer.Get()
defer chunkedbuffer.Put(cb)
isGzipped, err := sw.ReadData(cb)
if err != nil {
return nil, err
}
// in case of error buffer cannot be returned back to the pool
// See https://pkg.go.dev/net/http#RoundTripper
defer chunkedbuffer.Put(cb)
var bb bytesutil.ByteBuffer
err = sw.readFromBuffer(&bb, cb, isGzipped)
@@ -466,8 +468,8 @@ func (sw *scrapeWork) scrapeInternal(scrapeTimestamp, realTimestamp int64) error
body := leveledbytebufferpool.Get(sw.prevBodyLen)
if err == nil {
err = sw.readFromBuffer(body, cb, isGzipped)
chunkedbuffer.Put(cb)
}
chunkedbuffer.Put(cb)
bodyLen := len(body.B)
sw.prevBodyLen = bodyLen