Merge pull request 'Add backoff to handle slow android socket setup' (#1) from android_backoff into trunk
Reviewed-on: #1
This commit is contained in:
commit
5996d426c1
16
tor/tor.go
16
tor/tor.go
|
@ -173,11 +173,25 @@ func Start(ctx context.Context, conf *StartConf) (*Tor, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = tor.startProcess(ctx, conf)
|
err = tor.startProcess(ctx, conf)
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
// Connect the controller
|
// Connect the controller
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
for attempts := 0; attempts < 10; attempts++ {
|
||||||
err = tor.connectController(ctx, conf)
|
err = tor.connectController(ctx, conf)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
// backoff and retry
|
||||||
|
// max is 1 + 2 + 3 + 4 + 5...+10 = ~55 seconds
|
||||||
|
// After which point there is probably something else very wrong
|
||||||
|
// TODO: It might be worth breaking out the error here so that we can distinguish a
|
||||||
|
// slow socket (on e.g. Android) with a failed setup.
|
||||||
|
time.Sleep(time.Duration(int(time.Second) * attempts))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt eager auth w/ no password
|
// Attempt eager auth w/ no password
|
||||||
if err == nil && !conf.DisableEagerAuth {
|
if err == nil && !conf.DisableEagerAuth {
|
||||||
err = tor.Control.Authenticate("")
|
err = tor.Control.Authenticate("")
|
||||||
|
|
Loading…
Reference in New Issue