Skip to content

Commit

Permalink
fix: slow down auth loops to be nicer to cpus
Browse files Browse the repository at this point in the history
  • Loading branch information
carlmontanari committed Nov 25, 2024
1 parent 7ea22c0 commit d216749
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions channel/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d216749

Please sign in to comment.