소스 검색

Merge pull request #29893 from cpuguy83/fix_race_in_plugin_activation

Fix race accessing plugin storage map
Akihiro Suda 8 년 전
부모
커밋
2e3a621523
1개의 변경된 파일8개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 1
      pkg/plugins/plugins.go

+ 8 - 1
pkg/plugins/plugins.go

@@ -221,6 +221,10 @@ func loadWithRetry(name string, retry bool) (*Plugin, error) {
 		}
 		}
 
 
 		storage.Lock()
 		storage.Lock()
+		if pl, exists := storage.plugins[name]; exists {
+			storage.Unlock()
+			return pl, pl.activate()
+		}
 		storage.plugins[name] = pl
 		storage.plugins[name] = pl
 		storage.Unlock()
 		storage.Unlock()
 
 
@@ -298,7 +302,10 @@ func GetAll(imp string) ([]*Plugin, error) {
 	chPl := make(chan *plLoad, len(pluginNames))
 	chPl := make(chan *plLoad, len(pluginNames))
 	var wg sync.WaitGroup
 	var wg sync.WaitGroup
 	for _, name := range pluginNames {
 	for _, name := range pluginNames {
-		if pl, ok := storage.plugins[name]; ok {
+		storage.Lock()
+		pl, ok := storage.plugins[name]
+		storage.Unlock()
+		if ok {
 			chPl <- &plLoad{pl, nil}
 			chPl <- &plLoad{pl, nil}
 			continue
 			continue
 		}
 		}