fix: close connection when reconnect

This commit is contained in:
奶爸 2020-02-09 22:04:59 +08:00
parent 70f0e92343
commit b497b29402

View File

@ -59,10 +59,6 @@ func run(cmd *cobra.Command, args []string) {
ClientID: clientID,
ClientSecret: clientSecret,
}
retry := func() {
time.Sleep(delayWhenError)
log.Println("Try to reconnect ...")
}
// 上报服务器信息
go reportState()
@ -71,6 +67,15 @@ func run(cmd *cobra.Command, args []string) {
var conn *grpc.ClientConn
var hc pb.NezhaService_HeartbeatClient
retry := func() {
log.Println("Error to close connection ...")
if conn != nil {
conn.Close()
}
time.Sleep(delayWhenError)
log.Println("Try to reconnect ...")
}
for {
conn, err = grpc.Dial(server, grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
if err != nil {