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