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

Add minimum delay before posting UpstreamProxyError notice

- In practise, with fast failures, the 2*workerPoolSize
  condition would still result in spurious errors.
Rod Hynes 5 лет назад
Родитель
Сommit
69bb1d95c1
2 измененных файлов с 14 добавлено и 7 удалено
  1. 4 2
      psiphon/common/parameters/clientParameters.go
  2. 10 5
      psiphon/controller.go

+ 4 - 2
psiphon/common/parameters/clientParameters.go

@@ -86,7 +86,8 @@ const (
 	StaggerConnectionWorkersPeriod                   = "StaggerConnectionWorkersPeriod"
 	StaggerConnectionWorkersJitter                   = "StaggerConnectionWorkersJitter"
 	LimitIntensiveConnectionWorkers                  = "LimitIntensiveConnectionWorkers"
-	UpstreamProxyErrorWaitDuration                   = "UpstreamProxyErrorWaitDuration"
+	UpstreamProxyErrorMinWaitDuration                = "UpstreamProxyErrorMinWaitDuration"
+	UpstreamProxyErrorMaxWaitDuration                = "UpstreamProxyErrorMaxWaitDuration"
 	IgnoreHandshakeStatsRegexps                      = "IgnoreHandshakeStatsRegexps"
 	PrioritizeTunnelProtocolsProbability             = "PrioritizeTunnelProtocolsProbability"
 	PrioritizeTunnelProtocols                        = "PrioritizeTunnelProtocols"
@@ -282,7 +283,8 @@ var defaultClientParameters = map[string]struct {
 	StaggerConnectionWorkersPeriod:           {value: time.Duration(0), minimum: time.Duration(0)},
 	StaggerConnectionWorkersJitter:           {value: 0.1, minimum: 0.0},
 	LimitIntensiveConnectionWorkers:          {value: 0, minimum: 0},
-	UpstreamProxyErrorWaitDuration:           {value: 30 * time.Second, minimum: time.Duration(0)},
+	UpstreamProxyErrorMinWaitDuration:        {value: 10 * time.Second, minimum: time.Duration(0)},
+	UpstreamProxyErrorMaxWaitDuration:        {value: 30 * time.Second, minimum: time.Duration(0)},
 	IgnoreHandshakeStatsRegexps:              {value: false},
 	TunnelOperateShutdownTimeout:             {value: 1 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
 	TunnelPortForwardDialTimeout:             {value: 10 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},

+ 10 - 5
psiphon/controller.go

@@ -1691,22 +1691,27 @@ loop:
 
 			p := controller.config.GetClientParameters().Get()
 			workerPoolSize := p.Int(parameters.ConnectionWorkerPoolSize)
-			waitDuration := p.Duration(parameters.UpstreamProxyErrorWaitDuration)
+			minWaitDuration := p.Duration(parameters.UpstreamProxyErrorMinWaitDuration)
+			maxWaitDuration := p.Duration(parameters.UpstreamProxyErrorMaxWaitDuration)
 			p.Close()
 
 			controller.concurrentEstablishTunnelsMutex.Lock()
 			establishConnectTunnelCount := controller.establishConnectTunnelCount
 			controller.concurrentEstablishTunnelsMutex.Unlock()
 
-			// Delay until either UpstreamProxyErrorWaitDuration has elapsed (excluding
-			// time spent waiting for network connectivity) or, to post sooner if many
+			// Delay UpstreamProxyErrorMinWaitDuration (excluding time spent waiting
+			// for network connectivity) and then until either
+			// UpstreamProxyErrorMaxWaitDuration has elapsed or, to post sooner if many
 			// candidates are failing, at least workerPoolSize tunnel connection
 			// attempts have completed. We infer that at least workerPoolSize
 			// candidates have completed by checking that at least 2*workerPoolSize
 			// candidates have started.
 
-			if time.Since(candidateServerEntry.adjustedEstablishStartTime) < waitDuration &&
-				establishConnectTunnelCount < 2*workerPoolSize {
+			elapsedTime := time.Since(candidateServerEntry.adjustedEstablishStartTime)
+
+			if elapsedTime < minWaitDuration ||
+				(elapsedTime < maxWaitDuration &&
+					establishConnectTunnelCount < 2*workerPoolSize) {
 				return
 			}