From f96a24f13d8c8c8b15815a3408fb6d4e742eb255 Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Tue, 6 Aug 2019 20:11:32 +0100 Subject: [PATCH] Fix nil pointer when the session breaks --- cmd/ck-client/ck-client.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/ck-client/ck-client.go b/cmd/ck-client/ck-client.go index e00d922..b345868 100644 --- a/cmd/ck-client/ck-client.go +++ b/cmd/ck-client/ck-client.go @@ -47,18 +47,19 @@ func makeSession(sta *client.State) *mux.Session { connectingIP = "[" + connectingIP + "]" } remoteConn, err := d.Dial("tcp", connectingIP+":"+sta.RemotePort) - - if err != nil { - log.WithField("error", err).Error("Failed to connect to remote") - } - sk, err := client.PrepareConnection(sta, remoteConn) - _sessionKey.Store(sk) if err != nil { log.Errorf("Failed to establish new connections to remote: %v", err) // TODO increase the interval if failed multiple times time.Sleep(time.Second * 3) goto makeconn } + sk, err := client.PrepareConnection(sta, remoteConn) + if err != nil { + log.Errorf("Failed to prepare connection to remote: %v", err) + time.Sleep(time.Second * 3) + goto makeconn + } + _sessionKey.Store(sk) connsCh <- remoteConn wg.Done() }()