fix(tunneling): Adjust exponential backoff duration

This commit is contained in:
TwiN
2025-09-30 14:27:38 -04:00
parent 405c15f756
commit c7f0a32135
4 changed files with 7 additions and 4 deletions

View File

@@ -131,11 +131,11 @@ func (t *SSHTunnel) Dial(network, addr string) (net.Conn, error) {
}
// Attempt dial with exponential backoff retry
const maxRetries = 3
const baseDelay = time.Second
const baseDelay = 500 * time.Millisecond
var lastErr error
for attempt := 0; attempt < maxRetries; attempt++ {
if attempt > 0 {
// Exponential backoff: 1s, 2s, 4s
// Exponential backoff: 500ms, 1s, 2s
delay := baseDelay << (attempt - 1)
time.Sleep(delay)
// Close stale connection and reconnect

View File

@@ -13,7 +13,7 @@ type Config struct {
// Tunnels is a map of SSH tunnel configurations in which the key is the name of the tunnel
Tunnels map[string]*sshtunnel.Config `yaml:",inline"`
mu sync.RWMutex `yaml:"-"`
mu sync.RWMutex `yaml:"-"`
connections map[string]*sshtunnel.SSHTunnel `yaml:"-"`
}

View File

@@ -188,4 +188,4 @@ func TestConfig_Close(t *testing.T) {
if len(config.connections) != 0 {
t.Errorf("Close() did not clear connections map, got %d connections", len(config.connections))
}
}
}