Fix nil pointer when the session breaks

This commit is contained in:
Qian Wang 2019-08-06 20:11:32 +01:00
parent e15536d7c7
commit f96a24f13d
1 changed files with 7 additions and 6 deletions

View File

@ -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()
}()