Skip to content

Commit

Permalink
Add locks for populateCache which is racy and panics
Browse files Browse the repository at this point in the history
in a concurrent environment
  • Loading branch information
Joakim Henriksson committed Oct 25, 2016
1 parent f8b106b commit 19b882b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ovsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var intfUpdateLock sync.RWMutex
var bridgeCacheUpdateLock sync.RWMutex
var portCacheUpdateLock sync.RWMutex
var intfCacheUpdateLock sync.RWMutex
var populateCacheLock sync.RWMutex

// GetOVSClient is used for
func GetOVSClient(contype, endpoint string) (OvsClient, error) {
Expand Down Expand Up @@ -242,6 +243,8 @@ func (client *ovsClient) removeOvsObjCacheByRow(objtype, uuid string) error {
}

func populateCache(updates libovsdb.TableUpdates) (err error) {
populateCacheLock.Lock()
defer populateCacheLock.Unlock()
for table, tableUpdate := range updates.Updates {
if _, ok := cache[table]; !ok {
cache[table] = make(map[string]libovsdb.Row)
Expand Down

0 comments on commit 19b882b

Please sign in to comment.