flow/conn: Make the RTT accurate if a remote end doesn't reply to
a healthCheckMessage.
Now the RTT returned will be:
max(lastRTT, timeWaitingForHealthCurrentHealthCheckResponse)
Change-Id: I0b70b7d6a9cac7556af88270b3e26ccf0af18b36
diff --git a/runtime/internal/flow/conn/conn.go b/runtime/internal/flow/conn/conn.go
index 64fca19..29b833a 100644
--- a/runtime/internal/flow/conn/conn.go
+++ b/runtime/internal/flow/conn/conn.go
@@ -360,7 +360,13 @@
func (c *Conn) RTT() time.Duration {
defer c.mu.Unlock()
c.mu.Lock()
- return c.hcstate.lastRTT
+ rtt := c.hcstate.lastRTT
+ if !c.hcstate.requestSent.IsZero() {
+ if waitRTT := time.Since(c.hcstate.requestSent); waitRTT > rtt {
+ rtt = waitRTT
+ }
+ }
+ return rtt
}
func (c *Conn) initializeHealthChecks(ctx *context.T, firstRTT time.Duration) {
@@ -401,6 +407,7 @@
c.hcstate.requestTimer.Reset(timeout / 2)
c.hcstate.requestDeadline = time.Now().Add(timeout / 2)
c.hcstate.lastRTT = time.Since(c.hcstate.requestSent)
+ c.hcstate.requestSent = time.Time{}
}
}
diff --git a/runtime/internal/flow/conn/conn_test.go b/runtime/internal/flow/conn/conn_test.go
index 1b65dc7..263f826 100644
--- a/runtime/internal/flow/conn/conn_test.go
+++ b/runtime/internal/flow/conn/conn_test.go
@@ -91,7 +91,6 @@
go doWrite(t, df, payload)
af := <-flows
- ctx.Infof("%v, %v", df.Conn().RTT(), af.Conn().RTT())
if df.Conn().RTT() == 0 {
t.Errorf("dialed conn's RTT should be non-zero")
}