From 23a04e8472e3937bc01150d4a4415f1e59f0e21f Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Tue, 7 Apr 2026 09:54:17 +0300 Subject: [PATCH] Reduce SSH poll interval to 200ms with immediate probe Change sshWaitPollInterval from 2s to 200ms and probe immediately on entry before starting the ticker. This avoids wasting up to one full poll interval when SSH becomes ready between ticks. Co-Authored-By: Claude Opus 4.6 (1M context) --- ssh/client.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ssh/client.go b/ssh/client.go index 2ad51f2..c24deec 100644 --- a/ssh/client.go +++ b/ssh/client.go @@ -24,7 +24,7 @@ import ( const ( // sshWaitPollInterval is the interval between SSH readiness polls. - sshWaitPollInterval = 2 * time.Second + sshWaitPollInterval = 200 * time.Millisecond // defaultSSHTimeout is the default timeout for SSH connection attempts. defaultSSHTimeout = 10 * time.Second @@ -232,10 +232,21 @@ func (c *Client) WaitForReady(ctx context.Context) error { "user", c.user, ) + // Probe immediately before starting the ticker to avoid wasting + // up to one full poll interval when SSH is already ready. + probeCount := 1 + if err := c.probe(ctx); err == nil { + span.SetAttributes(attribute.Int("ssh.probes_total", probeCount)) + slog.Info("SSH is ready", + "host", c.host, + "port", c.port, + ) + return nil + } + ticker := time.NewTicker(sshWaitPollInterval) defer ticker.Stop() - probeCount := 0 for { select { case <-ctx.Done():