VOL-3383 - concurrent data access issues
Change-Id: I0050a179dda293e62756e75c01328390ed1ca38c
diff --git a/rw_core/core/adapter/agent.go b/rw_core/core/adapter/agent.go
index 3490081..7189cff 100644
--- a/rw_core/core/adapter/agent.go
+++ b/rw_core/core/adapter/agent.go
@@ -48,14 +48,14 @@
// No attempt is made to save the time to the db, so only recent times are guaranteed to be accurate.
func (aa *agent) updateCommunicationTime(new time.Time) {
// only update if new time is not in the future, and either the old time is invalid or new time > old time
+ aa.lock.Lock()
+ defer aa.lock.Unlock()
if last, err := ptypes.Timestamp(aa.adapter.LastCommunication); !new.After(time.Now()) && (err != nil || new.After(last)) {
timestamp, err := ptypes.TimestampProto(new)
if err != nil {
return // if the new time cannot be encoded, just ignore it
}
- aa.lock.Lock()
- defer aa.lock.Unlock()
aa.adapter.LastCommunication = timestamp
}
}
diff --git a/rw_core/utils/request_queue.go b/rw_core/utils/request_queue.go
index 2c95e23..c96a6a0 100644
--- a/rw_core/utils/request_queue.go
+++ b/rw_core/utils/request_queue.go
@@ -88,7 +88,12 @@
return ctx.Err()
case <-waitingOn:
- // lock is acquired
+ // Previous request has signaled that it is complete.
+ // This request now can proceed as the active
+ // request
+
+ rq.mutex.Lock()
+ defer rq.mutex.Unlock()
rq.current = r
return nil
}