Skip to content

[PECO-1687] Fixed the issue of infinite blocking in case of invalid credentials #399

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/databricks-sql-python.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/databricks/sql/auth/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MaxRetryDurationError,
NonRecoverableNetworkError,
OperationalError,
AuthenticationFailureError,
SessionAlreadyClosedError,
UnsafeToRetryError,
)
Expand Down Expand Up @@ -326,7 +327,7 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
This limit prevents automatically retrying non-idempotent commands that could
be destructive.
5. The request received a 403 response, because this can never succeed.

6. The request received a 401 response, because the User credentials are invalid

Q: What about OSErrors and Redirects?
A: urllib3 automatically retries in both scenarios
Expand All @@ -339,6 +340,11 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
if status_code == 200:
return False, "200 codes are not retried"

# Don't retry as there is an authentication error
if status_code == 401:
raise AuthenticationFailureError(
"Received 401 - UNAUTHORIZED. Authentication is required and has failed or has not yet been provided."
)
if status_code == 403:
raise NonRecoverableNetworkError(
"Received 403 - FORBIDDEN. Confirm your authentication credentials."
Expand Down
4 changes: 4 additions & 0 deletions src/databricks/sql/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class NonRecoverableNetworkError(RequestError):
"""Thrown if an HTTP code 501 is received"""


class AuthenticationFailureError(RequestError):
"""Thrown if an HTTP code 401 is received"""


class UnsafeToRetryError(RequestError):
"""Thrown if ExecuteStatement request receives a code other than 200, 429, or 503"""

Expand Down
Loading