From 594ed499ef629f5ff4b4b354aabc12bc80876b30 Mon Sep 17 00:00:00 2001
From: Hao Duan <duanhao0814@gmail.com>
Date: Tue, 26 May 2020 18:09:00 +0800
Subject: [PATCH] ethstats: avoid blocking chan when received invalid stats
 request (#21073)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* ethstats: avoid blocking chan when received invalid stats request

* ethstats: minor code polishes

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
---
 ethstats/ethstats.go | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go
index 27b90a5699..4445951221 100644
--- a/ethstats/ethstats.go
+++ b/ethstats/ethstats.go
@@ -312,8 +312,11 @@ func (s *Service) readLoop(conn *websocket.Conn) {
 			request, ok := msg["emit"][1].(map[string]interface{})
 			if !ok {
 				log.Warn("Invalid stats history request", "msg", msg["emit"][1])
-				s.histCh <- nil
-				continue // Ethstats sometime sends invalid history requests, ignore those
+				select {
+				case s.histCh <- nil: // Treat it as an no indexes request
+				default:
+				}
+				continue
 			}
 			list, ok := request["list"].([]interface{})
 			if !ok {
@@ -341,7 +344,7 @@ func (s *Service) readLoop(conn *websocket.Conn) {
 	}
 }
 
-// nodeInfo is the collection of metainformation about a node that is displayed
+// nodeInfo is the collection of meta information about a node that is displayed
 // on the monitoring page.
 type nodeInfo struct {
 	Name     string `json:"name"`
-- 
GitLab