From 2413a56408c707b5cb66bf82e86d49150b21353f Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Fri, 6 Oct 2017 16:46:31 +0800 Subject: [PATCH] avoid double close the channel --- client.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index f3dfe19..4e31066 100644 --- a/client.go +++ b/client.go @@ -62,7 +62,11 @@ func (cc *Client) Run() error { go func() { cc.err = cc.sshConn.Wait() Log(DEBUG, "connection hang up") - close(cc.ch) + //close(cc.ch) + select { + case cc.ch <- struct{}{}: + default: + } }() // wait exit signal @@ -304,7 +308,11 @@ func (cc *Client) keepAlive(interval time.Duration, maxCount int) { //cc.sshConn.Close() //cc.conn.Close() // send exit signal - close(cc.ch) + // close(cc.ch) + select { + case cc.ch <- struct{}{}: + default: + } return } } @@ -318,6 +326,10 @@ func (cc *Client) registerSignal() { case s1 := <-c: cc.err = fmt.Errorf("signal %v", s1) Log(ERROR, "signal %d received, exit", s1) - close(cc.ch) + //close(cc.ch) + select { + case cc.ch <- struct{}{}: + default: + } } }