1kasa commented on code in PR #3635:
URL: https://github.com/apache/dubbo-go/pull/3635#discussion_r3836399810
##########
remoting/nacos/builder.go:
##########
@@ -43,6 +44,55 @@ var (
newNacosConfigClient = nacosClient.NewNacosConfigClient
)
+// credentialIDs maps each distinct credential set to a small opaque id used
+// in pool keys. The credentials themselves stay in this process-local map and
+// never become part of the key, which may end up in logs.
+var (
+ credentialIDsMu sync.Mutex
+ credentialIDs = make(map[string]string)
+)
+
+func credentialID(url *common.URL) string {
+ tuple := strings.Join([]string{
+ url.GetParam(constant.NacosUsername, ""),
+ url.GetParam(constant.NacosPassword, ""),
+ url.GetParam(constant.NacosAccessKey, ""),
+ url.GetParam(constant.NacosSecretKey, ""),
+ }, "\n")
+ credentialIDsMu.Lock()
+ defer credentialIDsMu.Unlock()
+ id, ok := credentialIDs[tuple]
+ if !ok {
+ id = "cred" + strconv.Itoa(len(credentialIDs))
+ credentialIDs[tuple] = id
+ }
+ return id
+}
+
+// nacosClientPoolKey derives the gost client-pool key from the fields that
+// distinguish one nacos connection from another: server (endpoint/address),
+// namespace and the full credential set. Components pointing at the same
+// cluster (registry, config-center, metadata-report) resolve to the same key
+// and share one SDK client session instead of each opening its own.
+// Role-scoped client names must not be used as the key — they would defeat
+// the sharing.
+func nacosClientPoolKey(kind string, url *common.URL) string {
+ // GetNacosConfig ignores url.Location when an endpoint is set; mirror
+ // that here so URLs resolving to the same server set share one client.
+ server := url.GetParam(constant.NacosEndpoint, "")
+ if server == "" {
+ server = url.Location
+ }
Review Comment:
This is a suggestion, you can verify it. In my impression, url.Location may
contain multiple addresses (separated by commas), but the endpoint is a single
address. This will result in different locations generating different keys,
even if they point to the same cluster.
##########
remoting/nacos/builder.go:
##########
@@ -43,6 +44,55 @@ var (
newNacosConfigClient = nacosClient.NewNacosConfigClient
)
+// credentialIDs maps each distinct credential set to a small opaque id used
+// in pool keys. The credentials themselves stay in this process-local map and
+// never become part of the key, which may end up in logs.
+var (
+ credentialIDsMu sync.Mutex
Review Comment:
credentialIDsMu use sync.RWMutex
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]