mirror of
https://github.com/rancher/norman.git
synced 2025-09-03 08:14:40 +00:00
Fix concurrent map read/write
Problem: If you set a resource's labels to a global/shared map variable, norman will modify that map by adding a label. In race conditions, this can cause a concurrent map read/write panic. Solution: Copy the map in norman before modifying it.
This commit is contained in:
@@ -102,6 +102,13 @@ func (p *ObjectClient) Create(o runtime.Object) (runtime.Object, error) {
|
|||||||
labels := obj.GetLabels()
|
labels := obj.GetLabels()
|
||||||
if labels == nil {
|
if labels == nil {
|
||||||
labels = make(map[string]string)
|
labels = make(map[string]string)
|
||||||
|
} else {
|
||||||
|
ls := make(map[string]string)
|
||||||
|
for k, v := range labels {
|
||||||
|
ls[k] = v
|
||||||
|
}
|
||||||
|
labels = ls
|
||||||
|
|
||||||
}
|
}
|
||||||
labels["cattle.io/creator"] = "norman"
|
labels["cattle.io/creator"] = "norman"
|
||||||
obj.SetLabels(labels)
|
obj.SetLabels(labels)
|
||||||
|
Reference in New Issue
Block a user