Browse Source

Fix: negative tunnel durations in client stats

Rod Hynes 8 years ago
parent
commit
4d55aec8e7
1 changed files with 7 additions and 0 deletions
  1. 7 0
      psiphon/tunnel.go

+ 7 - 0
psiphon/tunnel.go

@@ -1207,6 +1207,13 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 
 		tunnelDuration := tunnel.conn.GetLastActivityMonotime().Sub(tunnel.establishedTime)
 
+		// tunnelDuration can be < 0 when tunnel.establishedTime is recorded after the
+		// last tunnel.conn.Read() succeeds. In that case, the last read would be the
+		// handshake response, so the tunnel had, essentially, no duration.
+		if tunnelDuration < 0 {
+			tunnelDuration = 0
+		}
+
 		err := RecordTunnelStat(
 			tunnel.serverContext.sessionId,
 			tunnel.serverContext.tunnelNumber,