From 478a25533e992190c7a93863e094536e7bfa3212 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 22 Mar 2019 16:48:14 +0000 Subject: [PATCH 1/2] [panic] fix ping message panic #617 Signed-off-by: Leo Chen --- api/proto/discovery/pingpong.go | 12 +++++++----- node/node_handler.go | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/proto/discovery/pingpong.go b/api/proto/discovery/pingpong.go index 5c156bbca..f8a0cffb3 100644 --- a/api/proto/discovery/pingpong.go +++ b/api/proto/discovery/pingpong.go @@ -14,11 +14,11 @@ import ( "bytes" "encoding/gob" "fmt" - "log" "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/api/proto" "github.com/harmony-one/harmony/api/proto/node" + "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/p2p" ) @@ -107,7 +107,8 @@ func GetPingMessage(payload []byte) (*PingMessageType, error) { err := decoder.Decode(ping) if err != nil { - log.Panic("Can't deserialize Ping message") + utils.GetLogInstance().Error("[GetPingMessage] Decode", "error", err) + return nil, fmt.Errorf("Decode Ping Error") } return ping, nil @@ -124,7 +125,8 @@ func GetPongMessage(payload []byte) (*PongMessageType, error) { err := decoder.Decode(pong) if err != nil { - log.Panic("Can't deserialize Pong message") + utils.GetLogInstance().Error("[GetPongMessage] Decode", "error", err) + return nil, fmt.Errorf("Decode Pong Error") } return pong, nil @@ -138,7 +140,7 @@ func (p PingMessageType) ConstructPingMessage() []byte { encoder := gob.NewEncoder(byteBuffer) err := encoder.Encode(p) if err != nil { - log.Panic("Can't serialize Ping message", "error:", err) + utils.GetLogInstance().Error("[ConstructPingMessage] Encode", "error", err) return nil } return byteBuffer.Bytes() @@ -152,7 +154,7 @@ func (p PongMessageType) ConstructPongMessage() []byte { encoder := gob.NewEncoder(byteBuffer) err := encoder.Encode(p) if err != nil { - log.Panic("Can't serialize Pong message", "error:", err) + utils.GetLogInstance().Error("[ConstructPongMessage] Encode", "error", err) return nil } return byteBuffer.Bytes() diff --git a/node/node_handler.go b/node/node_handler.go index f0715bbd0..f23c7d518 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -358,7 +358,7 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender string) int { ping, err := proto_discovery.GetPingMessage(msgPayload) if err != nil { - utils.GetLogInstance().Error("Can't get Ping Message") + utils.GetLogInstance().Error("Can't get Ping Message", "error", err) return -1 } @@ -448,7 +448,7 @@ func (node *Node) SendPongMessage() { func (node *Node) pongMessageHandler(msgPayload []byte) int { pong, err := proto_discovery.GetPongMessage(msgPayload) if err != nil { - utils.GetLogInstance().Error("Can't get Pong Message") + utils.GetLogInstance().Error("Can't get Pong Message", "error", err) return -1 } From aa1bd672c4a07abd685ca888b6f62a602b193fa6 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 20 Mar 2019 22:29:00 +0000 Subject: [PATCH 2/2] [misc] additional log in ping message Signed-off-by: Leo Chen --- node/node_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node_handler.go b/node/node_handler.go index f23c7d518..ea639965e 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -429,7 +429,7 @@ func (node *Node) SendPongMessage() { utils.GetLogInstance().Error("[PONG] failed to send pong message", "group", node.NodeConfig.GetShardGroupID()) continue } else { - utils.GetLogInstance().Info("[PONG] sent pong message to", "group", node.NodeConfig.GetShardGroupID()) + utils.GetLogInstance().Info("[PONG] sent pong message to", "group", node.NodeConfig.GetShardGroupID(), "# nodes", numPeersNow) } sentMessage = true // stop sending ping message