Skip to content

Commit b6e791b

Browse files
authored
Merge pull request #63 from stacklok/jaosorior/faster-ssh-poll
Reduce SSH poll interval to 500ms with immediate probe
2 parents bef1230 + 23a04e8 commit b6e791b

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

ssh/client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
const (
2626
// sshWaitPollInterval is the interval between SSH readiness polls.
27-
sshWaitPollInterval = 2 * time.Second
27+
sshWaitPollInterval = 200 * time.Millisecond
2828

2929
// defaultSSHTimeout is the default timeout for SSH connection attempts.
3030
defaultSSHTimeout = 10 * time.Second
@@ -232,10 +232,21 @@ func (c *Client) WaitForReady(ctx context.Context) error {
232232
"user", c.user,
233233
)
234234

235+
// Probe immediately before starting the ticker to avoid wasting
236+
// up to one full poll interval when SSH is already ready.
237+
probeCount := 1
238+
if err := c.probe(ctx); err == nil {
239+
span.SetAttributes(attribute.Int("ssh.probes_total", probeCount))
240+
slog.Info("SSH is ready",
241+
"host", c.host,
242+
"port", c.port,
243+
)
244+
return nil
245+
}
246+
235247
ticker := time.NewTicker(sshWaitPollInterval)
236248
defer ticker.Stop()
237249

238-
probeCount := 0
239250
for {
240251
select {
241252
case <-ctx.Done():

0 commit comments

Comments
 (0)