From d216749f27ad25c5e17bc7eaccea691705bd6306 Mon Sep 17 00:00:00 2001 From: Carl Montanari Date: Mon, 25 Nov 2024 11:53:19 -0800 Subject: [PATCH] fix: slow down auth loops to be nicer to cpus --- channel/auth.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/channel/auth.go b/channel/auth.go index 53c5007..134e29c 100644 --- a/channel/auth.go +++ b/channel/auth.go @@ -78,6 +78,13 @@ func (c *Channel) authenticateSSH(ctx context.Context, p, pp []byte) *result { return &result{nil, err} } + if nb == nil { + // nothing read, sleep a bit then try again + time.Sleep(c.ReadDelay) + + continue + } + b = append(b, nb...) err = c.sshMessageHandler(b) @@ -188,6 +195,13 @@ func (c *Channel) authenticateTelnet(ctx context.Context, u, p []byte) *result { return &result{nil, err} } + if nb == nil { + // nothing read, sleep a bit then try again + time.Sleep(c.ReadDelay) + + continue + } + b = append(b, nb...) if c.PromptPattern.Match(b) {