Skip to content

Commit

Permalink
[PECO-1687] Fixed the issue of infinite blocking in case of invalid c…
Browse files Browse the repository at this point in the history
…redentials
  • Loading branch information
jprakash-db committed Jun 17, 2024
1 parent a5b1ab0 commit 98fc645
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 1 deletion.
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

0 comments on commit 98fc645

Please sign in to comment.