Fix race in API related to LoadComplete()

LoadComplete() modifies object, so it would cause issues if it runs
concurrently with other methods. Uprage mutex locks to write
locks when LoadComplete() is being used.
This commit is contained in:
Andrey Smirnov
2017-12-13 12:40:06 +03:00
parent 9cb2a302f8
commit 43ddcd27cb
4 changed files with 32 additions and 32 deletions
+12 -12
View File
@@ -60,8 +60,8 @@ func apiPublishList(c *gin.Context) {
defer snapshotCollection.RUnlock()
collection := context.CollectionFactory().PublishedRepoCollection()
collection.RLock()
defer collection.RUnlock()
collection.Lock()
defer collection.Unlock()
result := make([]*deb.PublishedRepo, 0, collection.Len())
@@ -128,8 +128,8 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
var snapshot *deb.Snapshot
snapshotCollection := context.CollectionFactory().SnapshotCollection()
snapshotCollection.RLock()
defer snapshotCollection.RUnlock()
snapshotCollection.Lock()
defer snapshotCollection.Unlock()
for _, source := range b.Sources {
components = append(components, source.Component)
@@ -152,8 +152,8 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
var localRepo *deb.LocalRepo
localCollection := context.CollectionFactory().LocalRepoCollection()
localCollection.RLock()
defer localCollection.RUnlock()
localCollection.Lock()
defer localCollection.Unlock()
for _, source := range b.Sources {
components = append(components, source.Component)
@@ -253,12 +253,12 @@ func apiPublishUpdateSwitch(c *gin.Context) {
// published.LoadComplete would touch local repo collection
localRepoCollection := context.CollectionFactory().LocalRepoCollection()
localRepoCollection.RLock()
defer localRepoCollection.RUnlock()
localRepoCollection.Lock()
defer localRepoCollection.Unlock()
snapshotCollection := context.CollectionFactory().SnapshotCollection()
snapshotCollection.RLock()
defer snapshotCollection.RUnlock()
snapshotCollection.Lock()
defer snapshotCollection.Unlock()
collection := context.CollectionFactory().PublishedRepoCollection()
collection.Lock()
@@ -357,8 +357,8 @@ func apiPublishDrop(c *gin.Context) {
// published.LoadComplete would touch local repo collection
localRepoCollection := context.CollectionFactory().LocalRepoCollection()
localRepoCollection.RLock()
defer localRepoCollection.RUnlock()
localRepoCollection.Lock()
defer localRepoCollection.Unlock()
collection := context.CollectionFactory().PublishedRepoCollection()
collection.Lock()