mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-06 04:46:13 +02:00
tsdb: fix memory leaks in buffer pools (#17879)
* tsdb: fix memory leaks in buffer pools Clear reference fields when returning buffers to pools to avoid retaining data after the buffer is reused. Affected pools: - refSeriesPool: clear Labels - histogramsPool: clear H pointer - floatHistogramsPool: clear FH pointer - metadataPool: clear Unit and Help strings Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Clear slices Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Clear metadata buffer Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Remove tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> --------- Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
c4b0da94db
commit
dd85d7ca97
@ -214,6 +214,9 @@ func (h *Head) getRefSeriesBuffer() []record.RefSeries {
|
||||
}
|
||||
|
||||
func (h *Head) putRefSeriesBuffer(b []record.RefSeries) {
|
||||
for i := range b { // Zero out to avoid retaining label data.
|
||||
b[i].Labels = labels.EmptyLabels()
|
||||
}
|
||||
h.refSeriesPool.Put(b[:0])
|
||||
}
|
||||
|
||||
@ -257,6 +260,7 @@ func (h *Head) getHistogramBuffer() []record.RefHistogramSample {
|
||||
}
|
||||
|
||||
func (h *Head) putHistogramBuffer(b []record.RefHistogramSample) {
|
||||
clear(b)
|
||||
h.histogramsPool.Put(b[:0])
|
||||
}
|
||||
|
||||
@ -269,6 +273,7 @@ func (h *Head) getFloatHistogramBuffer() []record.RefFloatHistogramSample {
|
||||
}
|
||||
|
||||
func (h *Head) putFloatHistogramBuffer(b []record.RefFloatHistogramSample) {
|
||||
clear(b)
|
||||
h.floatHistogramsPool.Put(b[:0])
|
||||
}
|
||||
|
||||
@ -281,6 +286,7 @@ func (h *Head) getMetadataBuffer() []record.RefMetadata {
|
||||
}
|
||||
|
||||
func (h *Head) putMetadataBuffer(b []record.RefMetadata) {
|
||||
clear(b)
|
||||
h.metadataPool.Put(b[:0])
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user