From a06ed611ac7461ffa1fc728c065f2b08fe20e4c1 Mon Sep 17 00:00:00 2001 From: tnasu Date: Mon, 8 Nov 2021 12:59:47 +0900 Subject: [PATCH 1/3] Remove `default` case --- p2p/peer.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index a38dc4a79..97eb77070 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -404,13 +404,14 @@ func createMConnection( ChID: chID, Peer: p, Msg: copied}: - default: - // if the channel is full, we abandon this message - // Should check `config.Config.XxxBufSize` - p.Logger.Error("Lost the message since BaseReactor.recvMsgBuf is full", - "reactor", reactor, - "msgBytes.len", len(msgBytes), "msgBytes", fmt.Sprintf("%X", msgBytes)) - p.metrics.NumAbandonedPeerMsgs.With(labels...).Add(1) + // Remove `default` case since shouldn't abandon message although blocking sending message into golang channel + //default: + // // if the channel is full, we abandon this message + // // Should check `config.Config.XxxBufSize` + // p.Logger.Error("Lost the message since BaseReactor.recvMsgBuf is full", + // "reactor", reactor, + // "msgBytes.len", len(msgBytes), "msgBytes", fmt.Sprintf("%X", msgBytes)) + // p.metrics.NumAbandonedPeerMsgs.With(labels...).Add(1) } } else { reactor.Receive(chID, p, msgBytes) From 6178f78b1c19faf6864b5c93cd0004fb6efee90a Mon Sep 17 00:00:00 2001 From: tnasu Date: Mon, 8 Nov 2021 14:21:35 +0900 Subject: [PATCH 2/3] fix lint error: S1000: should use a simple channel send/receive instead of `select` with a single case (gosimple) --- p2p/peer.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index 97eb77070..45f7b5247 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -399,20 +399,23 @@ func createMConnection( // because msgBytes is on socket receive buffer yet so reactor can read it concurrently copied := make([]byte, len(msgBytes)) copy(copied, msgBytes) - select { - case ch <- &BufferedMsg{ - ChID: chID, - Peer: p, - Msg: copied}: - // Remove `default` case since shouldn't abandon message although blocking sending message into golang channel - //default: - // // if the channel is full, we abandon this message - // // Should check `config.Config.XxxBufSize` - // p.Logger.Error("Lost the message since BaseReactor.recvMsgBuf is full", - // "reactor", reactor, - // "msgBytes.len", len(msgBytes), "msgBytes", fmt.Sprintf("%X", msgBytes)) - // p.metrics.NumAbandonedPeerMsgs.With(labels...).Add(1) - } + ch <- &BufferedMsg{ChID: chID, Peer: p, Msg: copied} + /* + select { + case ch <- &BufferedMsg{ + ChID: chID, + Peer: p, + Msg: copied}: + // Remove `default` case since shouldn't abandon message although blocking sending message into golang channel + //default: + // // if the channel is full, we abandon this message + // // Should check `config.Config.XxxBufSize` + // p.Logger.Error("Lost the message since BaseReactor.recvMsgBuf is full", + // "reactor", reactor, + // "msgBytes.len", len(msgBytes), "msgBytes", fmt.Sprintf("%X", msgBytes)) + // p.metrics.NumAbandonedPeerMsgs.With(labels...).Add(1) + } + */ } else { reactor.Receive(chID, p, msgBytes) } From 4213c644a79e25f692366707edcd3d1ccfaf250f Mon Sep 17 00:00:00 2001 From: tnasu Date: Mon, 15 Nov 2021 13:37:43 +0900 Subject: [PATCH 3/3] (fix) Remove block comment and add a comment --- p2p/peer.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index 45f7b5247..29eda1bfb 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -399,23 +399,8 @@ func createMConnection( // because msgBytes is on socket receive buffer yet so reactor can read it concurrently copied := make([]byte, len(msgBytes)) copy(copied, msgBytes) + // if the channel is full, we are blocking a message until it can send into the channel ch <- &BufferedMsg{ChID: chID, Peer: p, Msg: copied} - /* - select { - case ch <- &BufferedMsg{ - ChID: chID, - Peer: p, - Msg: copied}: - // Remove `default` case since shouldn't abandon message although blocking sending message into golang channel - //default: - // // if the channel is full, we abandon this message - // // Should check `config.Config.XxxBufSize` - // p.Logger.Error("Lost the message since BaseReactor.recvMsgBuf is full", - // "reactor", reactor, - // "msgBytes.len", len(msgBytes), "msgBytes", fmt.Sprintf("%X", msgBytes)) - // p.metrics.NumAbandonedPeerMsgs.With(labels...).Add(1) - } - */ } else { reactor.Receive(chID, p, msgBytes) }