Skip to content

Commit

Permalink
Merge pull request #32 from free5gc/fix/terminate
Browse files Browse the repository at this point in the history
fix: terminate procedure
  • Loading branch information
ianchen0119 authored Jun 28, 2024
2 parents e098113 + 018ef43 commit fb0f449
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s *Server) Run(wg *sync.WaitGroup) {
if err != http.ErrServerClosed {
logger.SBILog.Panicf("HTTP server setup failed: %+v", err)
}
logger.SBILog.Infof("SBI server (listen on %s) stopped", s.httpServer.Addr)
}()
}

Expand Down
25 changes: 6 additions & 19 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (u *UdrApp) registerToNrf(ctx context.Context) error {
return nil
}

func (u *UdrApp) deregisterFromNrf() {
problemDetails, err := u.consumer.SendDeregisterNFInstance()
func (a *UdrApp) deregisterFromNrf() {
problemDetails, err := a.consumer.SendDeregisterNFInstance()
if problemDetails != nil {
logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails)
} else if err != nil {
Expand Down Expand Up @@ -167,41 +167,28 @@ func (a *UdrApp) Start() {
}
}()

a.wg.Add(1)
go a.listenShutdown(a.ctx)

a.sbiServer.Run(&a.wg)
a.WaitRoutineStopped()
}

func (a *UdrApp) listenShutdown(ctx context.Context) {
defer a.wg.Done()

<-ctx.Done()
a.terminateProcedure()
}

func (a *UdrApp) Terminate() {
logger.InitLog.Infof("Terminating UDR...")
a.cancel()

// deregister with NRF
a.deregisterFromNrf()
a.sbiServer.Shutdown()
logger.InitLog.Infof("UDR terminated")
}

func (a *UdrApp) terminateProcedure() {
logger.MainLog.Infof("Terminating UDR...")
a.CallServerStop()

// deregister with NRF
pd, err := a.Consumer().SendDeregisterNFInstance()
if pd != nil {
logger.MainLog.Errorf("Deregister NF instance Failed Problem[%+v]", pd)
} else if err != nil {
logger.MainLog.Errorf("Deregister NF instance Error[%+v]", err)
} else {
logger.MainLog.Infof("Deregister from NRF successfully")
}
logger.MainLog.Infof("UDR SBI Server terminated")
a.deregisterFromNrf()
}

func (a *UdrApp) CallServerStop() {
Expand Down

0 comments on commit fb0f449

Please sign in to comment.