From 4c763b6bc2687144633dbd1c8dc8460d65b3648d Mon Sep 17 00:00:00 2001 From: Rod Hynes Date: Mon, 11 Nov 2024 13:12:33 -0500 Subject: [PATCH] Reduce proxy max backoff delay - Also, log some delay info --- psiphon/common/inproxy/proxy.go | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/psiphon/common/inproxy/proxy.go b/psiphon/common/inproxy/proxy.go index da770c5f3..317c189e8 100644 --- a/psiphon/common/inproxy/proxy.go +++ b/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) } }