From 38df7faabc68c1d892b0ce5a2c5ec33592e95781 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 7 May 2019 23:02:56 +0200 Subject: [PATCH] Issue #184: fix data race in SendAsync This is a first attempt to fix the data race in SendAsync. Fixes #184 --- uasc/secure_channel.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/uasc/secure_channel.go b/uasc/secure_channel.go index 5ac31b20..605cbf68 100644 --- a/uasc/secure_channel.go +++ b/uasc/secure_channel.go @@ -228,6 +228,10 @@ func (s *SecureChannel) SendAsync(svc interface{}, authToken *ua.NodeID) (resp c if authToken == nil { authToken = ua.NewTwoByteNodeID(0) } + + s.mu.Lock() + defer s.mu.Unlock() + // the request header is always the first field val := reflect.ValueOf(svc) val.Elem().Field(0).Set(reflect.ValueOf(s.reqhdr)) @@ -263,9 +267,9 @@ func (s *SecureChannel) SendAsync(svc interface{}, authToken *ua.NodeID) (resp c // register the handler resp = make(chan Response) - s.mu.Lock() + // s.mu.Lock() s.handler[reqid] = resp - s.mu.Unlock() + //s.mu.Unlock() return resp, nil }