From 175a0715da4e9e40fdf730a0ed7db4da604746f1 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 29 Oct 2024 10:49:04 +0800 Subject: [PATCH] fix: use defer to subscribe the SDM svc --- internal/sbi/processor/pdu_session.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/sbi/processor/pdu_session.go b/internal/sbi/processor/pdu_session.go index 4e7cdbde..cb0bcede 100644 --- a/internal/sbi/processor/pdu_session.go +++ b/internal/sbi/processor/pdu_session.go @@ -121,16 +121,21 @@ func (p *Processor) HandlePDUSessionSMContextCreate( } } - if !p.Context().Ues.UeExists(smContext.Supi) { - if problemDetails, err := p.Consumer(). - Subscribe(ctx, smContext, smPlmnID); problemDetails != nil { - smContext.Log.Errorln("SDM Subscription Failed Problem:", problemDetails) - } else if err != nil { - smContext.Log.Errorln("SDM Subscription Error:", err) + var doSubscribe bool = false + defer func(){ + if doSubscribe { + if !p.Context().Ues.UeExists(smContext.Supi) { + if problemDetails, err := p.Consumer(). + Subscribe(ctx, smContext, smPlmnID); problemDetails != nil { + smContext.Log.Errorln("SDM Subscription Failed Problem:", problemDetails) + } else if err != nil { + smContext.Log.Errorln("SDM Subscription Error:", err) + } + } else { + p.Context().Ues.IncrementPduSessionCount(smContext.Supi) + } } - } else { - p.Context().Ues.IncrementPduSessionCount(smContext.Supi) - } + }() establishmentRequest := m.PDUSessionEstablishmentRequest if err := HandlePDUSessionEstablishmentRequest(smContext, establishmentRequest); err != nil { @@ -248,6 +253,7 @@ func (p *Processor) HandlePDUSessionSMContextCreate( smContext.PostRemoveDataPath() }() + doSubscribe = true response.JsonData = smContext.BuildCreatedData() c.Header("Location", smContext.Ref) c.Render(http.StatusCreated, openapi.MultipartRelatedRender{Data: response})