[VOL-5419] Added nil check in triggerFlowNotification function to fix crash
Signed-off-by: bseeniva <balaji.seenivasan@radisys.com>
Change-Id: Ia6b1a66f0a4098be3af9ad2adad5922cb7c6237a
diff --git a/internal/pkg/controller/device.go b/internal/pkg/controller/device.go
index abf3108..c8caddd 100644
--- a/internal/pkg/controller/device.go
+++ b/internal/pkg/controller/device.go
@@ -1097,8 +1097,12 @@
}
func (d *Device) triggerFlowNotification(cntx context.Context, cookie uint64, oper of.Command, bwDetails of.BwAvailDetails, err error) {
- flow, _ := d.GetFlow(cookie)
- d.triggerFlowResultNotification(cntx, cookie, flow, oper, bwDetails, err)
+ flow, ok := d.GetFlow(cookie)
+ if ok {
+ d.triggerFlowResultNotification(cntx, cookie, flow, oper, bwDetails, err)
+ } else {
+ logger.Warnw(ctx, "Flow not found", log.Fields{"device-id": d.ID, "Cookie": cookie})
+ }
}
func (d *Device) triggerFlowResultNotification(cntx context.Context, cookie uint64, flow *of.VoltSubFlow, oper of.Command, bwDetails of.BwAvailDetails, err error) {
@@ -1136,7 +1140,7 @@
if err := d.DelFlow(cntx, flow); err != nil {
logger.Warnw(ctx, "Delete Flow Error", log.Fields{"Cookie": flow.Cookie, "Reason": err.Error()})
}
- } else if !success {
+ } else if !success && flow != nil {
if d.IsFlowDelThresholdReached(flow.FlowCount, flow.Cookie) {
logger.Debugw(ctx, "Deleted flow from device and DB after delete threshold reached", log.Fields{"Cookie": cookie})
if err := d.DelFlow(cntx, flow); err != nil {