fix daemon cannot exit after alivetime
@@ -447,6 +447,7 @@ func (cd *clientDaemon) Serve() error {
if cd.Option.AliveTime.Duration > 0 {
g.Go(func() error {
+ for {
select {
case <-time.After(cd.Option.AliveTime.Duration):
var keepalives = []clientutil.KeepAlive{
@@ -457,16 +458,19 @@ func (cd *clientDaemon) Serve() error {
for _, keepalive := range keepalives {
if keepalive.Alive(cd.Option.AliveTime.Duration) {
keep = true
+ break
}
}
if !keep {
cd.Stop()
logger.Infof("alive time reached, stop daemon")
+ return nil
}
case <-cd.done:
logger.Infof("peer host done, stop watch alive time")
- }
return nil
+ }
+ }
})
}
