瀏覽代碼

libnet/datastore: stop sharing defaultScopes singleton

Each call to datastore.DefaultScopes() would modify and return the same
map. Consequently, some of the config for every NetworkController in the
process would be mutated each time one is constructed or reconfigured.
This behaviour is unexpected, unintended, and undesirable. Stop
accidentally sharing configuration by changing DefaultScopes() to return
a distinct map on each call.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 2 年之前
父節點
當前提交
8a20564847
共有 1 個文件被更改,包括 3 次插入4 次删除
  1. 3 4
      libnetwork/datastore/datastore.go

+ 3 - 4
libnetwork/datastore/datastore.go

@@ -154,13 +154,12 @@ var rootChain = defaultRootChain
 
 
 // DefaultScopes returns a map of default scopes and its config for clients to use.
 // DefaultScopes returns a map of default scopes and its config for clients to use.
 func DefaultScopes(dataDir string) map[string]*ScopeCfg {
 func DefaultScopes(dataDir string) map[string]*ScopeCfg {
+	s := makeDefaultScopes()
 	if dataDir != "" {
 	if dataDir != "" {
-		defaultScopes[LocalScope].Client.Address = dataDir + "/network/files/local-kv.db"
-		return defaultScopes
+		s[LocalScope].Client.Address = dataDir + "/network/files/local-kv.db"
 	}
 	}
 
 
-	defaultScopes[LocalScope].Client.Address = defaultPrefix + "/local-kv.db"
-	return defaultScopes
+	return s
 }
 }
 
 
 // IsValid checks if the scope config has valid configuration.
 // IsValid checks if the scope config has valid configuration.