Skip to content

Commit 5b7d3c1

Browse files
authored
Fix memory leak in distributor due to cluster label (#4739)
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent 454da6c commit 5b7d3c1

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* [BUGFIX] Query Frontend: If 'LogQueriesLongerThan' is set to < 0, log all queries as described in the docs. #4633
3636
* [BUGFIX] Distributor: update defaultReplicationStrategy to not fail with extend-write when a single instance is unhealthy. #4636
3737
* [BUGFIX] Distributor: Fix race condition on `/series` introduced by #4683. #4716
38+
* [BUGFIX] Distributor: Fix a memory leak in distributor due to the cluster label. #4739
3839

3940
## 1.11.0 2021-11-25
4041

pkg/distributor/ha_tracker.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ func findHALabels(replicaLabel, clusterLabel string, labels []cortexpb.LabelAdap
471471
replica = pair.Value
472472
}
473473
if pair.Name == clusterLabel {
474-
cluster = pair.Value
474+
// cluster label is unmarshalled into yoloString, which retains original remote write request body in memory.
475+
// Hence, we clone the yoloString to allow the request body to be garbage collected.
476+
cluster = util.StringsClone(pair.Value)
475477
}
476478
}
477479

pkg/util/strings.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package util
22

3+
import "unsafe"
4+
35
// StringsContain returns true if the search value is within the list of input values.
46
func StringsContain(values []string, search string) bool {
57
for _, v := range values {
@@ -19,3 +21,11 @@ func StringsMap(values []string) map[string]bool {
1921
}
2022
return out
2123
}
24+
25+
// StringsClone returns a copy input s
26+
// see: https://github.com/golang/go/blob/master/src/strings/clone.go
27+
func StringsClone(s string) string {
28+
b := make([]byte, len(s))
29+
copy(b, s)
30+
return *(*string)(unsafe.Pointer(&b))
31+
}

0 commit comments

Comments
 (0)