From dc4cb05a28f34a25d9fac5654f271fa07d129d1b Mon Sep 17 00:00:00 2001
From: "vito.he" <hxmhlt@163.com>
Date: Mon, 26 Aug 2019 11:30:41 +0800
Subject: [PATCH] Fix:url.Values is not safe map, so add the lock to avoid
 concurrent map read and map write error

---
 common/url.go | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/common/url.go b/common/url.go
index c594df235..0ef285d0e 100644
--- a/common/url.go
+++ b/common/url.go
@@ -27,6 +27,7 @@ import (
 	"net/url"
 	"strconv"
 	"strings"
+	"sync"
 )
 
 import (
@@ -64,11 +65,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
+	Params   url.Values
+	//url.Values is not safe map, add to avoid concurrent map read and map write error
+	paramsLock   sync.Mutex
 	PrimitiveURL string
 	ctx          context.Context
 }
@@ -283,14 +286,18 @@ func (c URL) Service() string {
 }
 
 func (c *URL) AddParam(key string, value string) {
+	c.paramsLock.Lock()
 	c.Params.Add(key, value)
+	c.paramsLock.Unlock()
 }
 
 func (c URL) GetParam(s string, d string) string {
 	var r string
+	c.paramsLock.Lock()
 	if r = c.Params.Get(s); r == "" {
 		r = d
 	}
+	c.paramsLock.Unlock()
 	return r
 }
 func (c URL) GetParamAndDecoded(key string) (string, error) {
-- 
GitLab