From af8d4a8c12fccf95329e85fda92ce391cb753656 Mon Sep 17 00:00:00 2001 From: he2 Date: Thu, 19 Sep 2019 09:17:32 +0800 Subject: [PATCH] fix: close health check tcp connection --- client/health.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/health.go b/client/health.go index ff2338f..12e35d9 100644 --- a/client/health.go +++ b/client/health.go @@ -2,15 +2,16 @@ package client import ( "container/heap" + "net" + "net/http" + "strings" + "time" + "github.com/cnlh/nps/lib/conn" "github.com/cnlh/nps/lib/file" "github.com/cnlh/nps/lib/sheap" "github.com/cnlh/nps/vender/github.com/astaxie/beego/logs" "github.com/pkg/errors" - "net" - "net/http" - "strings" - "time" ) var isStart bool @@ -70,7 +71,11 @@ func check(t *file.Health) { var rs *http.Response for _, v := range arr { if t.HealthCheckType == "tcp" { - _, err = net.DialTimeout("tcp", v, time.Duration(t.HealthCheckTimeout)*time.Second); + var c net.Conn + c, err = net.DialTimeout("tcp", v, time.Duration(t.HealthCheckTimeout)*time.Second) + if err == nil { + c.Close() + } } else { client := &http.Client{} client.Timeout = time.Duration(t.HealthCheckTimeout) * time.Second