This is an automated email from the ASF dual-hosted git repository.
fangyc pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new 944e6dc add lock for invocation attachment
new 382169c Merge pull request #288 from xujianhai666/fix-map-attach
944e6dc is described below
commit 944e6dc899f22f1b99f2afe57eb1794449bcb2aa
Author: xujianhai666 <[email protected]>
AuthorDate: Wed Dec 18 22:52:15 2019 +0800
add lock for invocation attachment
---
protocol/invocation/rpcinvocation.go | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/protocol/invocation/rpcinvocation.go
b/protocol/invocation/rpcinvocation.go
index 2124a22..bddd83b 100644
--- a/protocol/invocation/rpcinvocation.go
+++ b/protocol/invocation/rpcinvocation.go
@@ -19,6 +19,7 @@ package invocation
import (
"reflect"
+ "sync"
)
import (
@@ -37,6 +38,7 @@ type RPCInvocation struct {
callBack interface{}
attachments map[string]string
invoker protocol.Invoker
+ lock sync.RWMutex
}
func NewRPCInvocation(methodName string, arguments []interface{}, attachments
map[string]string) *RPCInvocation {
@@ -80,6 +82,8 @@ func (r *RPCInvocation) Attachments() map[string]string {
}
func (r *RPCInvocation) AttachmentsByKey(key string, defaultValue string)
string {
+ r.lock.RLock()
+ defer r.lock.RUnlock()
if r.attachments == nil {
return defaultValue
}
@@ -91,6 +95,8 @@ func (r *RPCInvocation) AttachmentsByKey(key string,
defaultValue string) string
}
func (r *RPCInvocation) SetAttachments(key string, value string) {
+ r.lock.Lock()
+ defer r.lock.Unlock()
if r.attachments == nil {
r.attachments = make(map[string]string)
}