Skip to content

Commit

Permalink
Merge pull request #186 from gopcua/issue-184-send-async-race
Browse files Browse the repository at this point in the history
Issue #184: fix data race in SendAsync
  • Loading branch information
magiconair authored May 8, 2019
2 parents 30ab0b8 + 38df7fa commit b11b575
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions uasc/secure_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b11b575

Please sign in to comment.