add isTimeoutErr for muxado compatibility

parent ba22424b
......@@ -77,6 +77,19 @@ var (
errSendBlocksStalled = errors.New("SendBlocks RPC timed and never received any blocks")
)
// isTimeoutErr is a helper function that returns true if err was caused by a
// network timeout.
func isTimeoutErr(err error) bool {
if err == nil {
return false
}
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
return true
}
// COMPATv1.3.0
return (err.Error() == "Read timeout" || err.Error() == "Write timeout")
}
// blockHistory returns up to 32 block ids, starting with recent blocks and
// then proving exponentially increasingly less recent blocks. The genesis
// block is always included as the last block. This block history can be used
......@@ -144,7 +157,7 @@ func (cs *ConsensusSet) managedReceiveBlocks(conn modules.PeerConn) (returnErr e
// needs to be chosen.
stalled := true
defer func() {
if netErr, ok := returnErr.(net.Error); ok && netErr.Timeout() && stalled {
if isTimeoutErr(returnErr) && stalled {
returnErr = errSendBlocksStalled
}
}()
......@@ -579,7 +592,7 @@ func (cs *ConsensusSet) threadedInitialBlockchainDownload() error {
return nil
}
numOutboundNotSynced++
if netErr, ok := err.(net.Error); !ok || !netErr.Timeout() {
if !isTimeoutErr(err) {
cs.log.Printf("WARN: disconnecting from peer %v because IBD failed: %v", p.NetAddress, err)
// Disconnect if there is an unexpected error (not a timeout). This
// includes errSendBlocksStalled.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment