[VOL-4045] Fix some race conditions in rw-core
This commit addresses only the race conditions seen during
testing.
Change-Id: I59859a5222c892453f3c089a181d4290e18f1863
diff --git a/VERSION b/VERSION
index dedcc7d..e0c9c37 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.9.1
+2.9.2-dev
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 9358d8a..7e401aa 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -328,7 +328,13 @@
defer cancel()
var desc string
operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
- defer agent.logDeviceUpdate(ctx, rpc, prevState, &agent.device.AdminState, operStatus, &desc)
+ defer func() {
+ currAdminState := prevState
+ if d, _ := agent.getDeviceReadOnly(ctx); d != nil {
+ currAdminState = &d.AdminState
+ }
+ agent.logDeviceUpdate(ctx, rpc, prevState, currAdminState, operStatus, &desc)
+ }()
var rpce *voltha.RPCEvent
defer func() {
if rpce != nil {
@@ -383,7 +389,6 @@
// enableDevice activates a preprovisioned or a disable device
func (agent *Agent) enableDevice(ctx context.Context) error {
//To preserve and use oldDevice state as prev state in new device
- prevDeviceState := agent.device.AdminState
var desc string
operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
@@ -394,6 +399,8 @@
}
logger.Debugw(ctx, "enable-device", log.Fields{"device-id": agent.deviceID})
+ prevDeviceState := agent.device.AdminState
+
oldDevice := agent.getDeviceReadOnlyWithoutLock()
if oldDevice.AdminState == voltha.AdminState_ENABLED {
diff --git a/rw_core/core/device/agent_device_update.go b/rw_core/core/device/agent_device_update.go
index 9e5013a..621e720 100644
--- a/rw_core/core/device/agent_device_update.go
+++ b/rw_core/core/device/agent_device_update.go
@@ -39,9 +39,8 @@
}
func (agent *Agent) stateChangeString(prevState *common.AdminState_Types, currState *common.AdminState_Types) string {
- device := agent.getDeviceReadOnlyWithoutLock()
if prevState != nil && currState != nil && *prevState != *currState {
- return fmt.Sprintf("%s->%s", *prevState, device.AdminState)
+ return fmt.Sprintf("%s->%s", *prevState, *currState)
}
return ""
}
diff --git a/rw_core/core/device/remote/adapter_proxy.go b/rw_core/core/device/remote/adapter_proxy.go
index ce4cf49..aba551e 100755
--- a/rw_core/core/device/remote/adapter_proxy.go
+++ b/rw_core/core/device/remote/adapter_proxy.go
@@ -30,18 +30,16 @@
// AdapterProxy represents adapter proxy attributes
type AdapterProxy struct {
kafka.EndpointManager
- deviceTopicRegistered bool
- coreTopic string
- kafkaICProxy kafka.InterContainerProxy
+ coreTopic string
+ kafkaICProxy kafka.InterContainerProxy
}
// NewAdapterProxy will return adapter proxy instance
func NewAdapterProxy(kafkaProxy kafka.InterContainerProxy, coreTopic string, endpointManager kafka.EndpointManager) *AdapterProxy {
return &AdapterProxy{
- EndpointManager: endpointManager,
- kafkaICProxy: kafkaProxy,
- coreTopic: coreTopic,
- deviceTopicRegistered: false,
+ EndpointManager: endpointManager,
+ kafkaICProxy: kafkaProxy,
+ coreTopic: coreTopic,
}
}
@@ -87,7 +85,6 @@
{Key: "device", Value: device},
}
replyToTopic := ap.getCoreTopic()
- ap.deviceTopicRegistered = true
logger.Debugw(ctx, "adoptDevice-send-request", log.Fields{"device-id": device.Id, "deviceType": device.Type, "serialNumber": device.SerialNumber})
return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...)
}
@@ -362,7 +359,6 @@
{Key: "request", Value: simulateReq},
}
replyToTopic := ap.getCoreTopic()
- ap.deviceTopicRegistered = true
return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, device.Id, args...)
}