chain: handle ZMQ timeout error correctly
This commit is contained in:
parent
5fb94231d0
commit
5f7060dadf
1 changed files with 18 additions and 14 deletions
|
@ -168,7 +168,7 @@ func (c *BitcoindConn) blockEventHandler(conn *gozmq.Conn) {
|
||||||
defer c.wg.Done()
|
defer c.wg.Done()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
log.Info("Started listening for bitcoind block notifications via ZMQ ",
|
log.Info("Started listening for bitcoind block notifications via ZMQ "+
|
||||||
"on", c.zmqBlockHost)
|
"on", c.zmqBlockHost)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -180,16 +180,18 @@ func (c *BitcoindConn) blockEventHandler(conn *gozmq.Conn) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll an event from the ZMQ socket. It's possible that the
|
// Poll an event from the ZMQ socket.
|
||||||
// connection to the socket continuously times out, so we'll
|
|
||||||
// prevent logging this error to prevent spamming the logs.
|
|
||||||
msgBytes, err := conn.Receive()
|
msgBytes, err := conn.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err, ok := err.(net.Error)
|
// It's possible that the connection to the socket
|
||||||
if !ok || !err.Timeout() {
|
// continuously times out, so we'll prevent logging this
|
||||||
log.Error(err)
|
// error to prevent spamming the logs.
|
||||||
|
netErr, ok := err.(net.Error)
|
||||||
|
if ok && netErr.Timeout() {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Errorf("Unable to receive ZMQ message: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +236,7 @@ func (c *BitcoindConn) txEventHandler(conn *gozmq.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
log.Info("Started listening for bitcoind transaction notifications "+
|
log.Info("Started listening for bitcoind transaction notifications "+
|
||||||
"via ZMQ on ", c.zmqTxHost)
|
"via ZMQ on", c.zmqTxHost)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Before attempting to read from the ZMQ socket, we'll make
|
// Before attempting to read from the ZMQ socket, we'll make
|
||||||
|
@ -245,16 +247,18 @@ func (c *BitcoindConn) txEventHandler(conn *gozmq.Conn) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll an event from the ZMQ socket. It's possible that the
|
// Poll an event from the ZMQ socket.
|
||||||
// connection to the socket continuously times out, so we'll
|
|
||||||
// prevent logging this error to prevent spamming the logs.
|
|
||||||
msgBytes, err := conn.Receive()
|
msgBytes, err := conn.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err, ok := err.(net.Error)
|
// It's possible that the connection to the socket
|
||||||
if !ok || !err.Timeout() {
|
// continuously times out, so we'll prevent logging this
|
||||||
log.Error(err)
|
// error to prevent spamming the logs.
|
||||||
|
netErr, ok := err.(net.Error)
|
||||||
|
if ok && netErr.Timeout() {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Errorf("Unable to receive ZMQ message: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue