Skip to content

Commit

Permalink
fix: ctrl^C not terminate
Browse files Browse the repository at this point in the history
  • Loading branch information
a3828162 committed Oct 17, 2024
1 parent f82f577 commit 560775a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 8 additions & 1 deletion internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
var registerNfInstanceRequest Nnrf_NFManagement.RegisterNFInstanceRequest
registerNfInstanceRequest.NfInstanceID = &udmContext.NfId
registerNfInstanceRequest.NrfNfManagementNfProfile = &nfProfile
var res *Nnrf_NFManagement.RegisterNFInstanceResponse
for {

Check failure on line 148 in internal/sbi/consumer/nrf_service.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary leading newline (whitespace)
var res *Nnrf_NFManagement.RegisterNFInstanceResponse

select {
case <-ctx.Done():
return "", "", errors.Errorf("Context Cancel before RegisterNFInstance")
default:
}

res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, &registerNfInstanceRequest)

if err != nil || res == nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ServerUdm interface {

Consumer() *consumer.Consumer
Processor() *processor.Processor
CancelContext() context.Context
}

type Server struct {
Expand Down Expand Up @@ -60,7 +61,7 @@ func (s *Server) Run(traceCtx context.Context, wg *sync.WaitGroup) error {
logger.SBILog.Info("Starting server...")

var err error
_, s.Context().NfId, err = s.Consumer().RegisterNFInstance(context.Background())
_, s.Context().NfId, err = s.Consumer().RegisterNFInstance(s.CancelContext())
if err != nil {
logger.InitLog.Errorf("UDM register to NRF Error[%s]", err.Error())
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func (a *UdmApp) WaitRoutineStopped() {
logger.MainLog.Infof("UDM App is terminated")
}

func (a *UdmApp) CancelContext() context.Context {
return a.ctx
}

func (a *UdmApp) Config() *factory.Config {
return a.cfg
}
Expand All @@ -183,10 +187,6 @@ func (a *UdmApp) Context() *udm_context.UDMContext {
return a.udmCtx
}

func (a *UdmApp) CancelContext() context.Context {
return a.ctx
}

func (a *UdmApp) Consumer() *consumer.Consumer {
return a.consumer
}
Expand Down

0 comments on commit 560775a

Please sign in to comment.