You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2019/08/27 05:25:00 UTC
[dubbo-go] branch 1.1 updated: Fix: add lock to protect
baseURL.params
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 1.1
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/1.1 by this push:
new e7c8dc6 Fix: add lock to protect baseURL.params
e7c8dc6 is described below
commit e7c8dc66c9175721078a683d1a96d0b847cd84bc
Author: vito.he <hx...@163.com>
AuthorDate: Mon Aug 26 19:38:48 2019 +0800
Fix: add lock to protect baseURL.params
---
common/url.go | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/common/url.go b/common/url.go
index c594df2..6e54536 100644
--- a/common/url.go
+++ b/common/url.go
@@ -64,11 +64,13 @@ func (t RoleType) Role() string {
}
type baseUrl struct {
- Protocol string
- Location string // ip+port
- Ip string
- Port string
- Params url.Values
+ Protocol string
+ Location string // ip+port
+ Ip string
+ Port string
+ //url.Values is not safe map, add to avoid concurrent map read and map write error
+ paramsLock sync.RWMutex
+ Params url.Values
PrimitiveURL string
ctx context.Context
}
@@ -288,9 +290,13 @@ func (c *URL) AddParam(key string, value string) {
func (c URL) GetParam(s string, d string) string {
var r string
- if r = c.Params.Get(s); r == "" {
+
+ c.paramsLock.RLock()
+ if r = c.Params.Get(s); len(r) == 0 {
r = d
}
+ c.paramsLock.RUnlock()
+
return r
}
func (c URL) GetParamAndDecoded(key string) (string, error) {