From c7f0a32135acbdae02d2c1b1f87d92bfaffa97e0 Mon Sep 17 00:00:00 2001 From: TwiN Date: Tue, 30 Sep 2025 14:27:38 -0400 Subject: [PATCH] fix(tunneling): Adjust exponential backoff duration --- README.md | 3 +++ config/tunneling/sshtunnel/sshtunnel.go | 4 ++-- config/tunneling/tunneling.go | 2 +- config/tunneling/tunneling_test.go | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 54a3e2a6..d584dd92 100644 --- a/README.md +++ b/README.md @@ -745,6 +745,9 @@ endpoints: - "[STATUS] == 200" ``` +> ⚠️ **WARNING**:: Tunneling may introduce additional latency, especially if the connection to the tunnel is retried frequently. +> This may lead to inaccurate response time measurements. + ### Alerting Gatus supports multiple alerting providers, such as Slack and PagerDuty, and supports different alerts for each diff --git a/config/tunneling/sshtunnel/sshtunnel.go b/config/tunneling/sshtunnel/sshtunnel.go index e0f0d258..964d5089 100644 --- a/config/tunneling/sshtunnel/sshtunnel.go +++ b/config/tunneling/sshtunnel/sshtunnel.go @@ -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 diff --git a/config/tunneling/tunneling.go b/config/tunneling/tunneling.go index f11676fc..c4f46d23 100644 --- a/config/tunneling/tunneling.go +++ b/config/tunneling/tunneling.go @@ -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:"-"` } diff --git a/config/tunneling/tunneling_test.go b/config/tunneling/tunneling_test.go index f80c7851..c28be5eb 100644 --- a/config/tunneling/tunneling_test.go +++ b/config/tunneling/tunneling_test.go @@ -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)) } -} \ No newline at end of file +}