From 3eb3ad32646e4a0aa44731c65175bcfec81df79c Mon Sep 17 00:00:00 2001 From: gnongs Date: Fri, 27 Oct 2023 15:44:45 +0900 Subject: [PATCH 1/4] Add closing the resp body. --- rpc/cosmos/health.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpc/cosmos/health.go b/rpc/cosmos/health.go index 6d76b2a..0a97f8e 100644 --- a/rpc/cosmos/health.go +++ b/rpc/cosmos/health.go @@ -22,5 +22,8 @@ func GetHealth(rpcAddr string) (int, error) { log.Error().Str("Response", "Error").Msg(fmt.Sprintf("%v", err)) return -1, err } + + defer resp.Body.Close() + return resp.StatusCode, nil } From 921959151725a90dfefda4de3d9d04bd83da75e7 Mon Sep 17 00:00:00 2001 From: gnongs Date: Fri, 27 Oct 2023 15:48:04 +0900 Subject: [PATCH 2/4] Add pprof package --- plugins/node_is_alived/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/node_is_alived/main.go b/plugins/node_is_alived/main.go index 901adb7..4498318 100644 --- a/plugins/node_is_alived/main.go +++ b/plugins/node_is_alived/main.go @@ -4,6 +4,9 @@ import ( "flag" "fmt" + "net/http" + _ "net/http/pprof" + health "github.com/dsrvlabs/vatz-plugin-cosmoshub/rpc/cosmos" pluginpb "github.com/dsrvlabs/vatz-proto/plugin/v1" "github.com/dsrvlabs/vatz/sdk" @@ -36,6 +39,10 @@ type HealthResult struct { } func main() { + go func() { + fmt.Println(http.ListenAndServe("localhost:6061", nil)) + }() + flag.StringVar(&addr, "addr", defaultAddr, "IP Address(e.g. 0.0.0.0, 127.0.0.1)") flag.IntVar(&port, "port", defaultPort, "Port number") flag.StringVar(&rpcAddr, "rpcAddr", defaultRPCAddr, "RPC addrest:port (e.g. http://127.0.0.1:26667)") From 9383c08a2c97d66ee9f5a1a2f7f604a5f1c31669 Mon Sep 17 00:00:00 2001 From: gnongs Date: Mon, 30 Oct 2023 11:38:31 +0900 Subject: [PATCH 3/4] Add the code that close HTTP client --- rpc/cosmos/api.go | 2 ++ rpc/cosmos/net_info.go | 2 ++ rpc/cosmos/validators.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/rpc/cosmos/api.go b/rpc/cosmos/api.go index fda93fd..10e37b5 100644 --- a/rpc/cosmos/api.go +++ b/rpc/cosmos/api.go @@ -74,6 +74,8 @@ func GetStatus(rpcAddr string) (*Status, error) { return nil, fmt.Errorf("request failed %s", string(rawBody)) } + defer resp.Body.Close() + status, err := parseRawStatus(rawBody) if err != nil { return nil, err diff --git a/rpc/cosmos/net_info.go b/rpc/cosmos/net_info.go index b23a89c..88a9764 100644 --- a/rpc/cosmos/net_info.go +++ b/rpc/cosmos/net_info.go @@ -102,6 +102,8 @@ func GetNpeers(rpcAddr string) (string, error) { return strconv.Itoa(resp.StatusCode), fmt.Errorf("request failed %s", string(rawBody)) } + defer resp.Body.Close() + info := netInfo{} err = json.Unmarshal(rawBody, &info) diff --git a/rpc/cosmos/validators.go b/rpc/cosmos/validators.go index 73640ae..abbd8b6 100644 --- a/rpc/cosmos/validators.go +++ b/rpc/cosmos/validators.go @@ -73,6 +73,8 @@ func GetBondStatus(rpcAddr string, valoperAddr string) (bool, error) { return false, fmt.Errorf("request failed %d %s", resp.StatusCode, string(rawBody)) } + defer resp.Body.Close() + status := validatorStatus{} err = json.Unmarshal(rawBody, &status) From 4b829164cabec6f2e480fa1d6706fbe185be3d8e Mon Sep 17 00:00:00 2001 From: gnongs Date: Mon, 30 Oct 2023 11:39:52 +0900 Subject: [PATCH 4/4] Remove pprof part --- plugins/node_is_alived/main.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugins/node_is_alived/main.go b/plugins/node_is_alived/main.go index 4498318..901adb7 100644 --- a/plugins/node_is_alived/main.go +++ b/plugins/node_is_alived/main.go @@ -4,9 +4,6 @@ import ( "flag" "fmt" - "net/http" - _ "net/http/pprof" - health "github.com/dsrvlabs/vatz-plugin-cosmoshub/rpc/cosmos" pluginpb "github.com/dsrvlabs/vatz-proto/plugin/v1" "github.com/dsrvlabs/vatz/sdk" @@ -39,10 +36,6 @@ type HealthResult struct { } func main() { - go func() { - fmt.Println(http.ListenAndServe("localhost:6061", nil)) - }() - flag.StringVar(&addr, "addr", defaultAddr, "IP Address(e.g. 0.0.0.0, 127.0.0.1)") flag.IntVar(&port, "port", defaultPort, "Port number") flag.StringVar(&rpcAddr, "rpcAddr", defaultRPCAddr, "RPC addrest:port (e.g. http://127.0.0.1:26667)")