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
andy89923 committed Jun 20, 2024
1 parent 1f94b8c commit 67a76a4
Show file tree
Hide file tree
Showing 3 changed files with 8 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 @@ -90,7 +90,6 @@ func action(cliCtx *cli.Context) error {
CHF = chf

chf.Start()
chf.WaitRoutineStopped()

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ func (s *Server) startServer(wg *sync.WaitGroup) {
if err != nil && err != http.ErrServerClosed {
logger.SBILog.Errorf("SBI server error: %v", err)
}
logger.SBILog.Warnf("SBI server (listen on %s) stopped", s.httpServer.Addr)
logger.SBILog.Infof("SBI server (listen on %s) stopped", s.httpServer.Addr)
}
9 changes: 7 additions & 2 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func (a *ChfApp) Start() {
if err := a.sbiServer.Run(context.Background(), &a.wg); err != nil {
logger.MainLog.Fatalf("Run SBI server failed: %+v", err)
}

a.WaitRoutineStopped()
}

func (a *ChfApp) listenShutdownEvent() {
Expand All @@ -163,12 +165,15 @@ func (a *ChfApp) listenShutdownEvent() {
}()

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

func (c *ChfApp) Terminate() {
logger.MainLog.Infof("Terminating CHF...")
c.cancel()
}

func (c *ChfApp) terminateProcedure() {
logger.MainLog.Infof("Terminating CHF...")
c.CallServerStop()

// deregister with NRF
Expand Down

0 comments on commit 67a76a4

Please sign in to comment.