fix: close connection when reconnect
This commit is contained in:
parent
70f0e92343
commit
b497b29402
@ -59,10 +59,6 @@ func run(cmd *cobra.Command, args []string) {
|
|||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
ClientSecret: clientSecret,
|
ClientSecret: clientSecret,
|
||||||
}
|
}
|
||||||
retry := func() {
|
|
||||||
time.Sleep(delayWhenError)
|
|
||||||
log.Println("Try to reconnect ...")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上报服务器信息
|
// 上报服务器信息
|
||||||
go reportState()
|
go reportState()
|
||||||
@ -71,6 +67,15 @@ func run(cmd *cobra.Command, args []string) {
|
|||||||
var conn *grpc.ClientConn
|
var conn *grpc.ClientConn
|
||||||
var hc pb.NezhaService_HeartbeatClient
|
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 {
|
for {
|
||||||
conn, err = grpc.Dial(server, grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
|
conn, err = grpc.Dial(server, grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user