chain: ensure eventType from ZMQ response is human-readable
In this commit, we fix a small issue where it's possible that we read a malformed message from the ZMQ connection to bitcoind due to it shutting down. To fix this, we ensure that the event type is human readable before attempting to log it.
This commit is contained in:
parent
d6155a55e9
commit
850ad0959a
1 changed files with 19 additions and 0 deletions
|
@ -221,6 +221,14 @@ func (c *BitcoindConn) blockEventHandler(conn *gozmq.Conn) {
|
||||||
}
|
}
|
||||||
c.rescanClientsMtx.Unlock()
|
c.rescanClientsMtx.Unlock()
|
||||||
default:
|
default:
|
||||||
|
// It's possible that the message wasn't fully read if
|
||||||
|
// bitcoind shuts down, which will produce an unreadable
|
||||||
|
// event type. To prevent from logging it, we'll make
|
||||||
|
// sure it conforms to the ASCII standard.
|
||||||
|
if !isASCII(eventType) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
log.Warnf("Received unexpected event type from "+
|
log.Warnf("Received unexpected event type from "+
|
||||||
"rawblock subscription: %v", eventType)
|
"rawblock subscription: %v", eventType)
|
||||||
}
|
}
|
||||||
|
@ -364,3 +372,14 @@ func (c *BitcoindConn) RemoveClient(id uint64) {
|
||||||
|
|
||||||
delete(c.rescanClients, id)
|
delete(c.rescanClients, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isASCII is a helper method that checks whether all bytes in `data` would be
|
||||||
|
// printable ASCII characters if interpreted as a string.
|
||||||
|
func isASCII(s string) bool {
|
||||||
|
for _, c := range s {
|
||||||
|
if c < 32 || c > 126 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue