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 { for {
select { select {
case <-c.C: case <-c.C:
_, _, err := cc.sshConn.SendRequest("keepalive@openssh.org", true, nil) resCh := make(chan error, 1)
if err != nil { go func(resCh chan error) {
Log(DEBUG, "keep alive error: %s", err.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++ count++
} else {
count = 0
} }
if count >= maxCount { if count >= maxCount {
cc.err = fmt.Errorf("keep alive detects connection hang up") cc.err = fmt.Errorf("keep alive detects connection hang up")
Log(ERROR, "keep alive hit max count, exit") Log(ERROR, "keep alive hit max count, exit")

Loading…
Cancel
Save