Преглед на файлове

rafthttp: not log expected timeout as error

The network timeout from stream with etcd 2.0 is expected because etcd
2.0 doesn't heartbeat on idle connections.
Yicheng Qin преди 11 години
родител
ревизия
fad2c09fa8
променени са 1 файла, в които са добавени 14 реда и са изтрити 1 реда
  1. 14 1
      rafthttp/stream.go

+ 14 - 1
rafthttp/stream.go

@@ -282,7 +282,15 @@ func (cr *streamReader) run() {
 			}
 			}
 		} else {
 		} else {
 			err := cr.decodeLoop(rc, t)
 			err := cr.decodeLoop(rc, t)
-			if err != io.EOF && !isClosedConnectionError(err) {
+			switch {
+			// all data is read out
+			case err == io.EOF:
+			// connection is closed by the remote
+			case isClosedConnectionError(err):
+			// stream msgapp is only used for etcd 2.0, and etcd 2.0 doesn't
+			// heartbeat on the idle stream, so it is expected to time out.
+			case t == streamTypeMsgApp && isNetworkTimeoutError(err):
+			default:
 				log.Printf("rafthttp: failed to read message on stream %s due to %v", t, err)
 				log.Printf("rafthttp: failed to read message on stream %s due to %v", t, err)
 			}
 			}
 		}
 		}
@@ -481,3 +489,8 @@ func checkStreamSupport(v *semver.Version, t streamType) bool {
 	}
 	}
 	return false
 	return false
 }
 }
+
+func isNetworkTimeoutError(err error) bool {
+	nerr, ok := err.(net.Error)
+	return ok && nerr.Timeout()
+}