avoid double close the channel

tls
fangdingjun 7 years ago
parent a64906e384
commit 2413a56408

@ -62,7 +62,11 @@ func (cc *Client) Run() error {
go func() { go func() {
cc.err = cc.sshConn.Wait() cc.err = cc.sshConn.Wait()
Log(DEBUG, "connection hang up") Log(DEBUG, "connection hang up")
close(cc.ch) //close(cc.ch)
select {
case cc.ch <- struct{}{}:
default:
}
}() }()
// wait exit signal // wait exit signal
@ -304,7 +308,11 @@ func (cc *Client) keepAlive(interval time.Duration, maxCount int) {
//cc.sshConn.Close() //cc.sshConn.Close()
//cc.conn.Close() //cc.conn.Close()
// send exit signal // send exit signal
close(cc.ch) // close(cc.ch)
select {
case cc.ch <- struct{}{}:
default:
}
return return
} }
} }
@ -318,6 +326,10 @@ func (cc *Client) registerSignal() {
case s1 := <-c: case s1 := <-c:
cc.err = fmt.Errorf("signal %v", s1) cc.err = fmt.Errorf("signal %v", s1)
Log(ERROR, "signal %d received, exit", s1) Log(ERROR, "signal %d received, exit", s1)
close(cc.ch) //close(cc.ch)
select {
case cc.ch <- struct{}{}:
default:
}
} }
} }

Loading…
Cancel
Save