Skip to content

Commit

Permalink
Add keep-alive loop exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jan 28, 2020
1 parent db9ce7a commit 875eb91
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,20 @@ func (rg *RouteGroup) keepAliveLoop(interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()

for range ticker.C {
lastSent := time.Unix(0, atomic.LoadInt64(&rg.lastSent))

if time.Since(lastSent) < interval {
continue
}

if err := rg.sendKeepAlive(); err != nil {
rg.logger.Warnf("Failed to send keepalive: %v", err)
for {
select {
case <-rg.closed:
return
case <-ticker.C:
lastSent := time.Unix(0, atomic.LoadInt64(&rg.lastSent))

if time.Since(lastSent) < interval {
continue
}

if err := rg.sendKeepAlive(); err != nil {
rg.logger.Warnf("Failed to send keepalive: %v", err)
}
}
}
}
Expand Down

0 comments on commit 875eb91

Please sign in to comment.