Skip to content

Commit

Permalink
fix: prevent app.Terminate() being called twice
Browse files Browse the repository at this point in the history
  • Loading branch information
yccodr committed Jun 25, 2024
1 parent 0e29e65 commit 201cb73
Show file tree
Hide file tree
Showing 2 changed files with 10 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 @@ -75,7 +75,6 @@ func action(cliCtx *cli.Context) error {
NSSF = nssf

nssf.Start()
nssf.Wait()

return nil
}
Expand Down
13 changes: 10 additions & 3 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type NssfApp struct {
nssfCtx *nssf_context.NSSFContext

ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
sbiServer *sbi.Server
processor *processor.Processor
Expand All @@ -41,14 +42,15 @@ func NewApp(ctx context.Context, cfg *factory.Config, tlsKeyLogPath string) (*Ns

nssf := &NssfApp{
cfg: cfg,
ctx: ctx,
wg: sync.WaitGroup{},
nssfCtx: nssf_context.GetSelf(),
}
nssf.SetLogEnable(cfg.GetLogEnable())
nssf.SetLogLevel(cfg.GetLogLevel())
nssf.SetReportCaller(cfg.GetLogReportCaller())

nssf.ctx, nssf.cancel = context.WithCancel(ctx)

processor := processor.NewProcessor(nssf)
nssf.processor = processor

Expand Down Expand Up @@ -159,19 +161,24 @@ func (a *NssfApp) Start() {
}()

a.sbiServer.Run(&a.wg)

go a.listenShutdown(a.ctx)
a.Wait()
}

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

func (a *NssfApp) Terminate() {
a.cancel()
}

func (a *NssfApp) terminateProcedure() {
logger.MainLog.Infof("Terminating NSSF...")
a.deregisterFromNrf()
a.sbiServer.Shutdown()
a.Wait()
}

func (a *NssfApp) Wait() {
Expand Down

0 comments on commit 201cb73

Please sign in to comment.