Просмотр исходного кода

Reduce proxy max backoff delay

- Also, log some delay info
Rod Hynes 1 год назад
Родитель
Сommit
4c763b6bc2
1 измененных файлов с 23 добавлено и 19 удалено
  1. 23 19
      psiphon/common/inproxy/proxy.go

+ 23 - 19
psiphon/common/inproxy/proxy.go

@@ -35,7 +35,7 @@ import (
 const (
 	proxyAnnounceDelay           = 1 * time.Second
 	proxyAnnounceDelayJitter     = 0.5
-	proxyAnnounceMaxBackoffDelay = 1 * time.Hour
+	proxyAnnounceMaxBackoffDelay = 1 * time.Minute
 	proxyAnnounceLogSampleSize   = 2
 	proxyAnnounceLogSamplePeriod = 30 * time.Minute
 	proxyWebRTCAnswerTimeout     = 20 * time.Second
@@ -386,24 +386,6 @@ func (p *Proxy) proxyClients(
 
 		if err != nil && ctx.Err() == nil {
 
-			// Limitation: the lastErrMsg string comparison isn't compatible
-			// with errors with minor variations, such as "unexpected
-			// response status code %d after %v" from
-			// InproxyBrokerRoundTripper.RoundTrip, with a time duration in
-			// the second parameter.
-			errMsg := err.Error()
-			if lastErrMsg != errMsg {
-				logErrorsCount = proxyAnnounceLogSampleSize
-				lastErrMsg = errMsg
-			}
-			if logErrorsCount > 0 {
-				p.config.Logger.WithTraceFields(
-					common.LogFields{
-						"error": errMsg,
-					}).Error("proxy client failed")
-				logErrorsCount -= 1
-			}
-
 			// Apply a simple exponential backoff based on whether
 			// proxyOneClient either relayed client traffic or got no match,
 			// or encountered a failure.
@@ -430,6 +412,28 @@ func (p *Proxy) proxyClients(
 				failureDelayFactor *= 2
 			}
 
+			// Sample error log.
+			//
+			// Limitation: the lastErrMsg string comparison isn't compatible
+			// with errors with minor variations, such as "unexpected
+			// response status code %d after %v" from
+			// InproxyBrokerRoundTripper.RoundTrip, with a time duration in
+			// the second parameter.
+			errMsg := err.Error()
+			if lastErrMsg != errMsg {
+				logErrorsCount = proxyAnnounceLogSampleSize
+				lastErrMsg = errMsg
+			}
+			if logErrorsCount > 0 {
+				p.config.Logger.WithTraceFields(
+					common.LogFields{
+						"error":  errMsg,
+						"delay":  delay,
+						"jitter": jitter,
+					}).Error("proxy client failed")
+				logErrorsCount -= 1
+			}
+
 			common.SleepWithJitter(ctx, delay, jitter)
 		}
 	}