Skip to content

Avoid reattempting authentication for auth versions where it has no effect #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tobgu
Copy link

@tobgu tobgu commented Jun 5, 2025

There are circumstances where the automatic authentication retry causes confusion and unexpected behaviour.

For example when the password is entered by a human and mistyped. If the underlying authentication system causes the user to be blocked after X attempts this will happen sooner than expected (after X/2 attempts).

This PR limits the retry to only happen for versions where it may have any actual positive effect (v2).

Copy link
Owner

@ncw ncw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice idea - thanks for implementing it.

I'm not sure the logic is correct though - please see comments inline.

@@ -494,7 +494,8 @@ func (c *Connection) authenticate(ctx context.Context) (err error) {
}
}

retries := 1
shouldReattempt := c.Auth.ShouldReattemptAuth()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't ever seem to be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't ever seem to be used?

It's checked on line 523 and assigned false on line 524, no?

@@ -519,8 +520,8 @@ again:
// Try again for a limited number of times on
// AuthorizationFailed or BadRequest. This allows us
// to try some alternate forms of the request
if (err == AuthorizationFailed || err == BadRequest) && retries > 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs the retries logic otherwise it will retry forever won't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs the retries logic otherwise it will retry forever won't it?

The inclusion of shouldReattempt in the if-condition and setting it to false if the condition evaluates to true should prevent infinite retries, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants