fix data race in storage (during addition)

pull/6/head
Nikhita Raghunath 2017-08-03 21:38:04 +05:30
parent 64a984bb62
commit 4a08a693b7
1 changed files with 11 additions and 2 deletions

View File

@ -343,8 +343,17 @@ func (r *crdHandler) getServingInfoFor(crd *apiextensions.CustomResourceDefiniti
storage: storage,
requestScope: requestScope,
}
storageMap[crd.UID] = ret
r.customStorage.Store(storageMap)
storageMap2 := make(crdStorageMap, len(storageMap))
// Copy because we cannot write to storageMap without a race
// as it is used without locking elsewhere
for k, v := range storageMap {
storageMap2[k] = v
}
storageMap2[crd.UID] = ret
r.customStorage.Store(storageMap2)
return ret
}