mirror of https://github.com/ehang-io/nps
fix: close health check tcp connection
parent
144f102935
commit
af8d4a8c12
|
@ -2,15 +2,16 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cnlh/nps/lib/conn"
|
"github.com/cnlh/nps/lib/conn"
|
||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/lib/sheap"
|
"github.com/cnlh/nps/lib/sheap"
|
||||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var isStart bool
|
var isStart bool
|
||||||
|
@ -70,7 +71,11 @@ func check(t *file.Health) {
|
||||||
var rs *http.Response
|
var rs *http.Response
|
||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if t.HealthCheckType == "tcp" {
|
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 {
|
} else {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
client.Timeout = time.Duration(t.HealthCheckTimeout) * time.Second
|
client.Timeout = time.Duration(t.HealthCheckTimeout) * time.Second
|
||||||
|
|
Loading…
Reference in New Issue