From 98fc645374a277b20b90a573ce94f4034ae2f316 Mon Sep 17 00:00:00 2001 From: Jothi Prakash Date: Mon, 17 Jun 2024 09:25:25 +0530 Subject: [PATCH 1/5] [PECO-1687] Fixed the issue of infinite blocking in case of invalid credentials --- .idea/.gitignore | 8 ++++++++ .idea/codeStyles/Project.xml | 7 +++++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .idea/databricks-sql-python.iml | 9 +++++++++ .idea/misc.xml | 9 +++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ src/databricks/sql/auth/retry.py | 8 +++++++- src/databricks/sql/exc.py | 4 ++++ 9 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/databricks-sql-python.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 000000000..919ce1f1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 000000000..a55e7a179 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/databricks-sql-python.iml b/.idea/databricks-sql-python.iml new file mode 100644 index 000000000..1193e260a --- /dev/null +++ b/.idea/databricks-sql-python.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..00c2bf78c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..d3d7ab093 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/databricks/sql/auth/retry.py b/src/databricks/sql/auth/retry.py index eee6f839e..24415490b 100644 --- a/src/databricks/sql/auth/retry.py +++ b/src/databricks/sql/auth/retry.py @@ -19,6 +19,7 @@ MaxRetryDurationError, NonRecoverableNetworkError, OperationalError, + AuthenticationFailureError, SessionAlreadyClosedError, UnsafeToRetryError, ) @@ -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 @@ -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." diff --git a/src/databricks/sql/exc.py b/src/databricks/sql/exc.py index 3b27283a4..eff98f38b 100644 --- a/src/databricks/sql/exc.py +++ b/src/databricks/sql/exc.py @@ -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""" From 1203a62dfe17ee8f089a7eebf9d03e919dd7322e Mon Sep 17 00:00:00 2001 From: Jothi Prakash Date: Mon, 17 Jun 2024 14:30:02 +0530 Subject: [PATCH 2/5] Incorporated the 401 status code error into the NonRecoverableNetworkError error handling --- .gitignore | 2 ++ src/databricks/sql/auth/retry.py | 9 ++------- src/databricks/sql/exc.py | 4 ---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index d89a4116a..682431225 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ # Icon must end with two \r Icon +# IntelliJ Files +.idea # Thumbnails ._* diff --git a/src/databricks/sql/auth/retry.py b/src/databricks/sql/auth/retry.py index 24415490b..1faf1222b 100644 --- a/src/databricks/sql/auth/retry.py +++ b/src/databricks/sql/auth/retry.py @@ -19,7 +19,6 @@ MaxRetryDurationError, NonRecoverableNetworkError, OperationalError, - AuthenticationFailureError, SessionAlreadyClosedError, UnsafeToRetryError, ) @@ -340,12 +339,8 @@ 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: + # Invalid Credentials error. Don't retry + if status_code == 403 or status_code == 401: raise NonRecoverableNetworkError( "Received 403 - FORBIDDEN. Confirm your authentication credentials." ) diff --git a/src/databricks/sql/exc.py b/src/databricks/sql/exc.py index eff98f38b..3b27283a4 100644 --- a/src/databricks/sql/exc.py +++ b/src/databricks/sql/exc.py @@ -105,10 +105,6 @@ 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""" From 594a85ad82318dc3c77631d218e87ec497049907 Mon Sep 17 00:00:00 2001 From: Jothi Prakash Date: Mon, 17 Jun 2024 14:33:05 +0530 Subject: [PATCH 3/5] Moved 401 error into a separate block --- src/databricks/sql/auth/retry.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/databricks/sql/auth/retry.py b/src/databricks/sql/auth/retry.py index 1faf1222b..a6daea81f 100644 --- a/src/databricks/sql/auth/retry.py +++ b/src/databricks/sql/auth/retry.py @@ -340,7 +340,13 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]: return False, "200 codes are not retried" # Invalid Credentials error. Don't retry - if status_code == 403 or status_code == 401: + if status_code == 401: + raise NonRecoverableNetworkError( + "Received 401 - FORBIDDEN. Invalid authentication credentials." + ) + + # Invalid Credentials error. Don't retry + if status_code == 403: raise NonRecoverableNetworkError( "Received 403 - FORBIDDEN. Confirm your authentication credentials." ) From c332bde899a753f726fe4d3ffcba4f201161250d Mon Sep 17 00:00:00 2001 From: Jothi Prakash Date: Tue, 18 Jun 2024 11:38:06 +0530 Subject: [PATCH 4/5] Removed the .idea file --- .idea/.gitignore | 8 -------- .idea/codeStyles/Project.xml | 7 ------- .idea/codeStyles/codeStyleConfig.xml | 5 ----- .idea/databricks-sql-python.iml | 9 --------- .idea/misc.xml | 9 --------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 7 files changed, 52 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/databricks-sql-python.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81b..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 919ce1f1f..000000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a179..000000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/databricks-sql-python.iml b/.idea/databricks-sql-python.iml deleted file mode 100644 index 1193e260a..000000000 --- a/.idea/databricks-sql-python.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 00c2bf78c..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index d3d7ab093..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfb..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 162ce1874f741747ca8bea4e64ec5032da1605ed Mon Sep 17 00:00:00 2001 From: Jothi Prakash Date: Mon, 8 Jul 2024 22:01:25 +0530 Subject: [PATCH 5/5] Fixed Linting using black --- src/databricks/sql/auth/retry.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/databricks/sql/auth/retry.py b/src/databricks/sql/auth/retry.py index 3c4125fd4..ae006deab 100755 --- a/src/databricks/sql/auth/retry.py +++ b/src/databricks/sql/auth/retry.py @@ -342,8 +342,6 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]: if status_code == 200: return False, "200 codes are not retried" - - # Invalid Credentials error. Don't retry if status_code == 401: raise NonRecoverableNetworkError(