From: Anssi Mannila Date: Mon, 4 Jul 2022 12:51:38 +0000 (+0300) Subject: Coverity issues fixed X-Git-Tag: 0.9.5~6 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=9c4697fa22fae79ac923e72f417ecbebf1c1e4d6;p=ric-plt%2Fsubmgr.git Coverity issues fixed Change-Id: I8406c565e99819bea8151d5b4902e7029013b5b6 Signed-off-by: Anssi Mannila --- diff --git a/pkg/control/control.go b/pkg/control/control.go index 4c0cf9a..49b7968 100755 --- a/pkg/control/control.go +++ b/pkg/control/control.go @@ -170,8 +170,14 @@ func NewControl() *Control { if readSubsFromDb == "true" { // Read subscriptions from db - c.ReadE2Subscriptions() - c.ReadRESTSubscriptions() + err := c.ReadE2Subscriptions() + if err != nil { + xapp.Logger.Error("ReadE2Subscriptions() failed %s", err.Error()) + } + err = c.ReadRESTSubscriptions() + if err != nil { + xapp.Logger.Error("ReadRESTSubscriptions() failed %s", err.Error()) + } } go xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler) @@ -179,7 +185,11 @@ func NewControl() *Control { } func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) { - subscriptions, _ := c.registry.QueryHandler() + subscriptions, err := c.registry.QueryHandler() + if err != nil { + xapp.Logger.Error("QueryHandler() failed %s", err.Error()) + } + xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json") } @@ -237,7 +247,10 @@ func (c *Control) ReadRESTSubscriptions() error { for restSubId, restSubscription := range restSubscriptions { restSubscription.SubReqOngoing = false restSubscription.SubDelReqOngoing = false - c.WriteRESTSubscriptionToSdl(restSubId, restSubscription) + err := c.WriteRESTSubscriptionToSdl(restSubId, restSubscription) + if err != nil { + xapp.Logger.Error("WriteRESTSubscriptionToSdl() failed:%s", err.Error()) + } } c.registry.restSubscriptions = restSubscriptions return nil @@ -667,8 +680,11 @@ func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e } } - xapp.Logger.Error("XAPP-SubReq E2 subscription failed %s", idstring(err, trans, subs)) - c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) + xapp.Logger.Error("XAPP-SubReq E2 subscription failed: %s", idstring(err, trans, subs)) + err2 := c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) + if err2 != nil { + xapp.Logger.Error("RemoveFromSubscription failed: %s", err2.Error()) + } return nil, &errorInfo, err } @@ -706,7 +722,10 @@ func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSu } c.UpdateCounter(cRestSubFailNotifToXapp) - xapp.Subscription.Notify(resp, *clientEndpoint) + err = xapp.Subscription.Notify(resp, *clientEndpoint) + if err != nil { + xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error()) + } // E2 is down. Delete completely processed request safely now if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false { @@ -741,7 +760,10 @@ func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubs xapp.Logger.Debug("Sending successful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) c.UpdateCounter(cRestSubNotifToXapp) - xapp.Subscription.Notify(resp, *clientEndpoint) + err := xapp.Subscription.Notify(resp, *clientEndpoint) + if err != nil { + xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error()) + } // E2 is down. Delete completely processed request safely now if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false { @@ -840,7 +862,10 @@ func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) - c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) + err = c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) + if err != nil { + xapp.Logger.Error("XAPP-SubDelReq %s:", idstring(fmt.Errorf("RemoveFromSubscription faliled"), trans, subs)) + } return xAppEventInstanceID, nil } @@ -983,7 +1008,10 @@ func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *Transaction if err == nil { trans.Release() c.UpdateCounter(cSubRespToXapp) - c.rmrSendToXapp("", subs, trans) + err := c.rmrSendToXapp("", subs, trans) + if err != nil { + xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error()) + } return } case *e2ap.E2APSubscriptionFailure: @@ -1061,7 +1089,10 @@ func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) { trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg) if err == nil { c.UpdateCounter(cSubDelRespToXapp) - c.rmrSendToXapp("", subs, trans) + err := c.rmrSendToXapp("", subs, trans) + if err != nil { + xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error()) + } } } @@ -1119,11 +1150,15 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran if err != nil { valid = false c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) + } // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) if valid == false { - c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c) + err = c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c) + if err != nil { + xapp.Logger.Error("RemoveFromSubscription() failed:%s", err.Error()) + } } parentTrans.SendEvent(subRfMsg, 0) @@ -1198,7 +1233,11 @@ func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *Transact } else { c.UpdateCounter(cSubReReqToE2) } - c.rmrSendToE2T(desc, subs, trans) + err := c.rmrSendToE2T(desc, subs, trans) + if err != nil { + xapp.Logger.Error("rmrSendToE2T() failed:%s", err.Error()) + } + if subs.DoNotWaitSubResp == false { event, timedOut = trans.WaitEvent(e2SubscriptionDirectives.E2TimeoutTimerValue) if timedOut { @@ -1243,7 +1282,10 @@ func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *Tr } else { c.UpdateCounter(cSubDelReReqToE2) } - c.rmrSendToE2T(desc, subs, trans) + err := c.rmrSendToE2T(desc, subs, trans) + if err != nil { + xapp.Logger.Error("SUBS-SubDelReq: rmrSendToE2T failure: %s", idstring(err, trans, subs, parentTrans)) + } event, timedOut = trans.WaitEvent(e2tSubDelReqTime) if timedOut { c.UpdateCounter(cSubDelReqTimerExpiry) @@ -1320,7 +1362,7 @@ func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) { //------------------------------------------------------------------- // handle from E2T Subscription Delete Response //------------------------------------------------------------------- -func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) { +func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) { xapp.Logger.Debug("MSG from E2T: %s", params.String()) c.UpdateCounter(cSubDelRespFromE2) subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload) diff --git a/pkg/control/debug_rest_if.go b/pkg/control/debug_rest_if.go index cc73c72..0d249d9 100644 --- a/pkg/control/debug_rest_if.go +++ b/pkg/control/debug_rest_if.go @@ -47,8 +47,14 @@ func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) { // This can be used to remove all subscriptions db from if s == "emptydb" { xapp.Logger.Debug("RemoveAllSubscriptionsFromSdl() called") - c.RemoveAllSubscriptionsFromSdl() - c.RemoveAllRESTSubscriptionsFromSdl() + err := c.RemoveAllSubscriptionsFromSdl() + if err != nil { + xapp.Logger.Error("RemoveAllSubscriptionsFromSdl() RemoveAllSubscriptionsFromSdl() failure: %s", err.Error()) + } + err = c.RemoveAllRESTSubscriptionsFromSdl() + if err != nil { + xapp.Logger.Error("RemoveAllRESTSubscriptionsFromSdl() RemoveAllSubscriptionsFromSdl() failure: %s", err.Error()) + } return } @@ -68,7 +74,10 @@ func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request // Get all REST Subscriptions in subscription manager xapp.Logger.Debug("GetAllRestSubscriptions() called") - w.Write(c.registry.GetAllRestSubscriptionsJson()) + _, err := w.Write(c.registry.GetAllRestSubscriptionsJson()) + if err != nil { + xapp.Logger.Error("GetAllRestSubscriptions() w.Write failure: %s", err.Error()) + } } func (c *Control) GetAllE2Nodes(w http.ResponseWriter, r *http.Request) { @@ -86,7 +95,10 @@ func (c *Control) GetAllE2NodeRestSubscriptions(w http.ResponseWriter, r *http.R ranName := pathParams["ranName"] xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() ranName=%s", ranName) if ranName != "" { - w.Write(c.registry.GetAllE2NodeRestSubscriptionsJson(ranName)) + _, err := w.Write(c.registry.GetAllE2NodeRestSubscriptionsJson(ranName)) + if err != nil { + xapp.Logger.Error("GetAllE2NodeRestSubscriptions() w.Write failure: %s", err.Error()) + } } else { xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() Invalid path %s", ranName) w.WriteHeader(400) // Bad request @@ -97,7 +109,10 @@ func (c *Control) GetAllXapps(w http.ResponseWriter, r *http.Request) { // Get all xApps in subscription manager xapp.Logger.Debug("GetAllXapps() called: Req= %v", r.URL.Path) - w.Write(c.registry.GetAllXappsJson()) + _, err := w.Write(c.registry.GetAllXappsJson()) + if err != nil { + xapp.Logger.Error("GetAllXapps() w.Write failure: %s", err.Error()) + } } func (c *Control) GetAllXappRestSubscriptions(w http.ResponseWriter, r *http.Request) { @@ -108,7 +123,10 @@ func (c *Control) GetAllXappRestSubscriptions(w http.ResponseWriter, r *http.Req xappServiceName := pathParams["xappServiceName"] xapp.Logger.Debug("GetAllXappRestSubscriptions() xappServiceName=%s", xappServiceName) if xappServiceName != "" { - w.Write(c.registry.GetAllXappRestSubscriptionsJson(xappServiceName)) + _, err := w.Write(c.registry.GetAllXappRestSubscriptionsJson(xappServiceName)) + if err != nil { + xapp.Logger.Error("GetAllXappRestSubscriptions() w.Write failure: %s", err.Error()) + } } else { xapp.Logger.Debug("GetAllXappRestSubscriptions() Invalid path %s", xappServiceName) w.WriteHeader(400) // Bad request @@ -177,6 +195,9 @@ func (c *Control) GetE2Subscriptions(w http.ResponseWriter, r *http.Request) { if err != nil { w.WriteHeader(404) // Not found } else { - w.Write(e2Subscriptions) + _, err := w.Write(e2Subscriptions) + if err != nil { + xapp.Logger.Error("GetE2Subscriptions() w.Write failure: %s", err.Error()) + } } } diff --git a/pkg/control/duplicate.go b/pkg/control/duplicate.go index 345a6f8..8b7dcdc 100644 --- a/pkg/control/duplicate.go +++ b/pkg/control/duplicate.go @@ -57,7 +57,10 @@ func (d *DuplicateCtrl) SetMd5sumFromLastOkRequest(restSubsId string, md5sum str return } - d.removeOngoingTransaction(md5sum) + err := d.removeOngoingTransaction(md5sum) + if err != nil { + xapp.Logger.Error("removeOngoingTransaction() failed:%s", err.Error()) + } prevRestSubsId, exists := d.previousRequestMap[md5sum] diff --git a/pkg/control/e2if_state.go b/pkg/control/e2if_state.go index 876dfc4..b86ef81 100644 --- a/pkg/control/e2if_state.go +++ b/pkg/control/e2if_state.go @@ -57,7 +57,10 @@ func (e *E2IfState) Init(c *Control) { e.control = c e.NbIdMap = make(map[string]string, 0) e.ReadE2ConfigurationFromRnib() - e.SubscribeChannels() + err := e.SubscribeChannels() + if err != nil { + xapp.Logger.Error("Init(): SubscribeChannels() failed: %v", err) + } } func (e *E2IfState) GetE2NodesJson() []byte { diff --git a/pkg/control/registry.go b/pkg/control/registry.go index 29d82a9..f9e1bcc 100644 --- a/pkg/control/registry.go +++ b/pkg/control/registry.go @@ -530,7 +530,9 @@ func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *Transaction if waitRouteClean > 0 { // Wait here that response is delivered to xApp via RMR before route is cleaned xapp.Logger.Debug("Pending %v in order to wait route cleanup", waitRouteClean) + r.mutex.Unlock() time.Sleep(waitRouteClean) + r.mutex.Lock() } xapp.Logger.Debug("CLEAN %s", subs.String()) @@ -567,7 +569,10 @@ func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *Transaction // Endpoint of merged subscription is being deleted xapp.Logger.Debug("Subscription route update WriteSubscriptionToDb") - c.WriteSubscriptionToDb(subs) + err := c.WriteSubscriptionToDb(subs) + if err != nil { + xapp.Logger.Error("tracker.UnTrackTransaction() failed:%s", err.Error()) + } c.UpdateCounter(cUnmergedSubscriptions) } return nil diff --git a/pkg/control/transaction.go b/pkg/control/transaction.go index f3d5c17..282d291 100644 --- a/pkg/control/transaction.go +++ b/pkg/control/transaction.go @@ -200,6 +200,9 @@ func (t *TransactionXapp) Release() { t.mutex.Unlock() if tracker != nil && xappkey != nil { - tracker.UnTrackTransaction(*xappkey) + _, err := tracker.UnTrackTransaction(*xappkey) + if err != nil { + xapp.Logger.Error("tracker.UnTrackTransaction() failed:%s", err.Error()) + } } }