fix keepalive issue

tls
fangdingjun 7 years ago
parent 3b9fb72ce3
commit a64906e384

@ -281,13 +281,23 @@ func (cc *Client) keepAlive(interval time.Duration, maxCount int) {
for {
select {
case <-c.C:
resCh := make(chan error, 1)
go func(resCh chan error) {
_, _, err := cc.sshConn.SendRequest("keepalive@openssh.org", true, nil)
resCh <- err
}(resCh)
select {
case err := <-resCh:
if err != nil {
Log(DEBUG, "keep alive error: %s", err.Error())
count++
} else {
count = 0
}
case <-time.After(3 * time.Second):
count++
}
if count >= maxCount {
cc.err = fmt.Errorf("keep alive detects connection hang up")
Log(ERROR, "keep alive hit max count, exit")

Loading…
Cancel
Save