Skip to content

Commit

Permalink
fix: teminate twice when call Terminate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-cs12-NYCU committed Jun 26, 2024
1 parent 1095f3f commit 6133423
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func action(cliCtx *cli.Context) error {
UDR = udr

udr.Start()
udr.Wait()

return nil
}
Expand Down
30 changes: 27 additions & 3 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ func (a *UdrApp) Start() {
a.deregisterFromNrf()
}
}()

go a.listenShutdown(a.ctx)

a.sbiServer.Run(&a.wg)
go a.listenShutdown(a.ctx)
a.WaitRoutineStopped()
}

func (a *UdrApp) listenShutdown(ctx context.Context) {
<-ctx.Done()
a.Terminate()
a.terminateProcedure()
}

func (a *UdrApp) Terminate() {
Expand All @@ -186,7 +188,29 @@ func (a *UdrApp) Terminate() {
logger.InitLog.Infof("UDR terminated")
}

func (a *UdrApp) Wait() {
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")
}

func (a *UdrApp) CallServerStop() {
if a.sbiServer != nil {
a.sbiServer.Shutdown()
}
}

func (a *UdrApp) WaitRoutineStopped() {
a.wg.Wait()
logger.MainLog.Infof("UDR terminated")
}

0 comments on commit 6133423

Please sign in to comment.