Merge pull request #21347 from karalabe/ethstats-fixes

ethstats: fix reconnection issue, implement primus pings
This commit is contained in:
Péter Szilágyi 2020-07-20 11:47:13 +03:00 committed by GitHub
commit 35ddf36229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -280,8 +280,10 @@ func (s *Service) loop() {
}
}
fullReport.Stop()
// Make sure the connection is closed
// Close the current connection and establish a new one
conn.Close()
errTimer.Reset(0)
}
}
}
@ -296,8 +298,23 @@ func (s *Service) readLoop(conn *websocket.Conn) {
for {
// Retrieve the next generic network packet and bail out on error
var blob json.RawMessage
if err := conn.ReadJSON(&blob); err != nil {
log.Warn("Failed to retrieve stats server message", "err", err)
return
}
// If the network packet is a system ping, respond to it directly
var ping string
if err := json.Unmarshal(blob, &ping); err == nil && strings.HasPrefix(ping, "primus::ping::") {
if err := conn.WriteJSON(strings.Replace(ping, "ping", "pong", -1)); err != nil {
log.Warn("Failed to respond to system ping message", "err", err)
return
}
continue
}
// Not a system ping, try to decode an actual state message
var msg map[string][]interface{}
if err := conn.ReadJSON(&msg); err != nil {
if err := json.Unmarshal(blob, &msg); err != nil {
log.Warn("Failed to decode stats server message", "err", err)
return
}