Browse Source

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 năm trước cách đây
mục cha
commit
8a20564847
1 tập tin đã thay đổi với 3 bổ sung4 xóa
  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.
 func DefaultScopes(dataDir string) map[string]*ScopeCfg {
+	s := makeDefaultScopes()
 	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.