Skip to content

Commit 35ddf36

Browse files
authored
Merge pull request #21347 from karalabe/ethstats-fixes
ethstats: fix reconnection issue, implement primus pings
2 parents 9e88224 + 0fef66c commit 35ddf36

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

ethstats/ethstats.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ func (s *Service) loop() {
280280
}
281281
}
282282
fullReport.Stop()
283-
// Make sure the connection is closed
283+
284+
// Close the current connection and establish a new one
284285
conn.Close()
286+
errTimer.Reset(0)
285287
}
286288
}
287289
}
@@ -296,8 +298,23 @@ func (s *Service) readLoop(conn *websocket.Conn) {
296298

297299
for {
298300
// Retrieve the next generic network packet and bail out on error
301+
var blob json.RawMessage
302+
if err := conn.ReadJSON(&blob); err != nil {
303+
log.Warn("Failed to retrieve stats server message", "err", err)
304+
return
305+
}
306+
// If the network packet is a system ping, respond to it directly
307+
var ping string
308+
if err := json.Unmarshal(blob, &ping); err == nil && strings.HasPrefix(ping, "primus::ping::") {
309+
if err := conn.WriteJSON(strings.Replace(ping, "ping", "pong", -1)); err != nil {
310+
log.Warn("Failed to respond to system ping message", "err", err)
311+
return
312+
}
313+
continue
314+
}
315+
// Not a system ping, try to decode an actual state message
299316
var msg map[string][]interface{}
300-
if err := conn.ReadJSON(&msg); err != nil {
317+
if err := json.Unmarshal(blob, &msg); err != nil {
301318
log.Warn("Failed to decode stats server message", "err", err)
302319
return
303320
}

0 commit comments

Comments
 (0)