Skip to content

Commit

Permalink
Reduce proxy max backoff delay
Browse files Browse the repository at this point in the history
- Also, log some delay info
  • Loading branch information
rod-hynes committed Nov 11, 2024
1 parent cf0f7c2 commit 4c763b6
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions psiphon/common/inproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 4c763b6

Please sign in to comment.