Skip to content

Commit

Permalink
fix: delete ticker when no urr depend (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 authored Apr 23, 2024
1 parent 0b15816 commit b068e1b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/forwarder/perio/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (pg *PERIOGroup) newTicker(wg *sync.WaitGroup, evtCh chan Event) error {
if pg.ticker != nil {
return errors.Errorf("ticker not nil")
}
logger.PerioLog.Infof("new ticker [%+v]", pg.period)

pg.ticker = time.NewTicker(pg.period)
pg.stopCh = make(chan struct{})
Expand Down Expand Up @@ -82,6 +83,7 @@ func (pg *PERIOGroup) newTicker(wg *sync.WaitGroup, evtCh chan Event) error {
}

func (pg *PERIOGroup) stopTicker() {
logger.PerioLog.Debugf("stopTicker: [%+v]", pg.period)
pg.stopCh <- struct{}{}
close(pg.stopCh)
}
Expand All @@ -102,7 +104,6 @@ func OpenServer(wg *sync.WaitGroup) (*Server, error) {

wg.Add(1)
go s.Serve(wg)
logger.PerioLog.Infof("perio server started")

return s, nil
}
Expand All @@ -120,6 +121,7 @@ func (s *Server) Handle(
}

func (s *Server) Serve(wg *sync.WaitGroup) {
logger.PerioLog.Infof("perio server started")
defer func() {
logger.PerioLog.Infof("perio server stopped")
close(s.evtCh)
Expand Down Expand Up @@ -164,9 +166,10 @@ func (s *Server) Serve(wg *sync.WaitGroup) {
if len(perioGroup.urrids[e.lSeid]) == 0 {
delete(perioGroup.urrids, e.lSeid)
if len(perioGroup.urrids) == 0 {
// If no urr for the ticker, this ticker could be stop and delete
perioGroup.stopTicker()
delete(s.perioList, period)
}
delete(s.perioList, period)
}
break
}
Expand Down

0 comments on commit b068e1b

Please sign in to comment.