summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatus Mrekaj <matus.mrekaj@pantheon.tech>2019-10-22 15:05:39 +0200
committerMatus Mrekaj <matus.mrekaj@pantheon.tech>2019-10-30 14:42:35 +0100
commit58601b470bbd4e5ef534fed83511aa5a7f1c2d1e (patch)
tree1c0c1176567d66e1b7be45c51f445dd5baa28dee /core
parentcc80dbcaaaca8bf1b6042fead850d456cf589a4e (diff)
fix data races in proxy server
Signed-off-by: Matus Mrekaj <matus.mrekaj@pantheon.tech> Change-Id: I932d560548ee816e28683243a7318a2a7fbbb24a
Diffstat (limited to 'core')
-rw-r--r--core/connection.go31
-rw-r--r--core/control_ping.go4
-rw-r--r--core/request_handler.go2
3 files changed, 22 insertions, 15 deletions
diff --git a/core/connection.go b/core/connection.go
index 6f82616..264ec43 100644
--- a/core/connection.go
+++ b/core/connection.go
@@ -111,6 +111,9 @@ type Connection struct {
lastReplyLock sync.Mutex // lock for the last reply
lastReply time.Time // time of the last received reply from VPP
+
+ msgControlPing api.Message
+ msgControlPingReply api.Message
}
func newConnection(binapi adapter.VppAPI, attempts int, interval time.Duration) *Connection {
@@ -122,14 +125,16 @@ func newConnection(binapi adapter.VppAPI, attempts int, interval time.Duration)
}
c := &Connection{
- vppClient: binapi,
- maxAttempts: attempts,
- recInterval: interval,
- codec: &codec.MsgCodec{},
- msgIDs: make(map[string]uint16),
- msgMap: make(map[uint16]api.Message),
- channels: make(map[uint16]*Channel),
- subscriptions: make(map[uint16][]*subscriptionCtx),
+ vppClient: binapi,
+ maxAttempts: attempts,
+ recInterval: interval,
+ codec: &codec.MsgCodec{},
+ msgIDs: make(map[string]uint16),
+ msgMap: make(map[uint16]api.Message),
+ channels: make(map[uint16]*Channel),
+ subscriptions: make(map[uint16][]*subscriptionCtx),
+ msgControlPing: msgControlPing,
+ msgControlPingReply: msgControlPingReply,
}
binapi.SetMsgCallback(c.msgCallback)
return c
@@ -314,7 +319,7 @@ func (c *Connection) healthCheckLoop(connChan chan ConnectionEvent) {
}
// send the control ping request
- ch.reqChan <- &vppRequest{msg: msgControlPing}
+ ch.reqChan <- &vppRequest{msg: c.msgControlPing}
for {
// expect response within timeout period
@@ -427,12 +432,12 @@ func (c *Connection) retrieveMessageIDs() (err error) {
}
n++
- if c.pingReqID == 0 && msg.GetMessageName() == msgControlPing.GetMessageName() {
+ if c.pingReqID == 0 && msg.GetMessageName() == c.msgControlPing.GetMessageName() {
c.pingReqID = msgID
- msgControlPing = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
- } else if c.pingReplyID == 0 && msg.GetMessageName() == msgControlPingReply.GetMessageName() {
+ c.msgControlPing = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
+ } else if c.pingReplyID == 0 && msg.GetMessageName() == c.msgControlPingReply.GetMessageName() {
c.pingReplyID = msgID
- msgControlPingReply = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
+ c.msgControlPingReply = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
}
if debugMsgIDs {
diff --git a/core/control_ping.go b/core/control_ping.go
index cd447b7..b39fd3f 100644
--- a/core/control_ping.go
+++ b/core/control_ping.go
@@ -1,6 +1,8 @@
package core
-import "git.fd.io/govpp.git/api"
+import (
+ "git.fd.io/govpp.git/api"
+)
var (
msgControlPing api.Message = new(ControlPing)
diff --git a/core/request_handler.go b/core/request_handler.go
index d3f7bdc..ddd5307 100644
--- a/core/request_handler.go
+++ b/core/request_handler.go
@@ -110,7 +110,7 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
if req.multi {
// send a control ping to determine end of the multipart response
- pingData, _ := c.codec.EncodeMsg(msgControlPing, c.pingReqID)
+ pingData, _ := c.codec.EncodeMsg(c.msgControlPing, c.pingReqID)
log.WithFields(logger.Fields{
"channel": ch.id,