all: fix bug when reconnecting

This commit is contained in:
fatedier 2016-04-07 19:27:39 +08:00
parent 6a0d6035cb
commit d5913fc77b
2 changed files with 6 additions and 2 deletions

View File

@ -72,7 +72,10 @@ func msgReader(cli *client.ProxyClient, c *conn.Conn, msgSendChan chan interface
log.Info("ProxyName [%s], try to reconnect to frps [%s:%d]...", cli.Name, client.ServerAddr, client.ServerPort) log.Info("ProxyName [%s], try to reconnect to frps [%s:%d]...", cli.Name, client.ServerAddr, client.ServerPort)
c, err = loginToServer(cli) c, err = loginToServer(cli)
if err == nil { if err == nil {
close(msgSendChan)
msgSendChan = make(chan interface{}, 1024)
go heartbeatSender(c, msgSendChan) go heartbeatSender(c, msgSendChan)
go msgSender(cli, c, msgSendChan)
break break
} }
@ -81,6 +84,7 @@ func msgReader(cli *client.ProxyClient, c *conn.Conn, msgSendChan chan interface
} }
time.Sleep(delayTime * time.Second) time.Sleep(delayTime * time.Second)
} }
continue
} else if err != nil { } else if err != nil {
log.Warn("ProxyName [%s], read from frps error: %v", cli.Name, err) log.Warn("ProxyName [%s], read from frps error: %v", cli.Name, err)
continue continue
@ -117,7 +121,7 @@ func msgSender(cli *client.ProxyClient, c *conn.Conn, msgSendChan chan interface
buf, _ := json.Marshal(msg) buf, _ := json.Marshal(msg)
err := c.Write(string(buf) + "\n") err := c.Write(string(buf) + "\n")
if err != nil { if err != nil {
log.Warn("ProxyName [%s], write to client error, proxy exit", cli.Name) log.Warn("ProxyName [%s], write to server error, proxy exit", cli.Name)
c.Close() c.Close()
break break
} }

View File

@ -158,7 +158,7 @@ func msgReader(s *server.ProxyServer, c *conn.Conn, msgSendChan chan interface{}
case consts.HeartbeatReq: case consts.HeartbeatReq:
log.Debug("ProxyName [%s], get heartbeat", s.Name) log.Debug("ProxyName [%s], get heartbeat", s.Name)
timer.Reset(time.Duration(server.HeartBeatTimeout) * time.Second) timer.Reset(time.Duration(server.HeartBeatTimeout) * time.Second)
heartbeatRes := msg.ControlRes{ heartbeatRes := &msg.ControlRes{
Type: consts.HeartbeatRes, Type: consts.HeartbeatRes,
} }
msgSendChan <- heartbeatRes msgSendChan <- heartbeatRes