Repository navigation
fix(auth): Cognito calls time out after a few seconds - #2072
Merged
Merged
Conversation
The Cognito client gives up after 2 s to connect and 3 s to read, with one retry. When Cognito does not answer or is busy, a signed-in request answers 503 with Retry-After and "Sign-in service is not answering. Try again in a moment." instead of 401, so the dashboard keeps the stored sign-in rather than discarding it, and the next page load after Cognito answers again restores the session. A token Cognito refuses still answers 401. - auth_service: botocore Config on the client (connect 2 s, read 3 s, standard retry mode, total_max_attempts 2). New CognitoUnavailable, raised only for a failed GetUser: botocore network and HTTP client errors, and a ClientError with a throttle or server-error code or a 5xx status. Every other failure keeps its ValueError, then 401. - deps.get_current_user, GET /auth/me and POST /auth/logout answer 503 with Retry-After: 2 for CognitoUnavailable. The results WebSocket keeps close code 4401. - The log line names the botocore class and a ClientError's error code, never the message. Resolves #2027 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn Signed-off-by: amarkanday <a.markanday@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #2027
What and why
The Cognito client gives up after 2 s to connect and 3 s to read, with one retry. When Cognito does not answer or is busy, a signed-in request answers 503 with Retry-After and "Sign-in service is not answering. Try again in a moment." instead of 401, so the dashboard keeps the stored sign-in rather than discarding it, and the next page load after Cognito answers again restores the session. A token Cognito refuses still answers 401.
Changes:
auth_service.py: a botocoreConfigon the Cognito client (connect 2 s, read 3 s, standard retry mode,total_max_attempts2). NewCognitoUnavailable(not aValueError), raised only for a failedGetUser: botocore network and HTTP client errors, and aClientErrorwith a throttle or server-error code (TooManyRequestsException,ThrottlingException,InternalErrorException,ServiceUnavailable) or a 5xx status. Everything else keeps today's path (ValueError, then 401).deps.get_current_user,GET /auth/meandPOST /auth/logoutanswer 503 withRetry-After: 2for it. The results WebSocket keeps close code 4401.ClientError, its error code. Never the message.No setting, no migration, no change to the dashboard's code (two new jest tests pin its current behaviour), no OpenAPI change (
make openapileaves the three snapshots unchanged). Other Cognito calls (sign-in, refresh, sign-up and so on) get the same timeouts and keep their error mapping. On the dashboard, a page load or reload while Cognito does not answer still lands on /login, with a message naming HTTP 503 and the request id, and keeps the token; making the dashboard retry instead is a separate change.Step-0 premise re-check at 373744b (main, after #2010)
boto3.client("cognito-idp"in backend/ and modules/, built lazily in theclientpropertyauth_service.py:172auth_service.py:172get_user_with_groupsandget_userturn every failure intoValueErrorauth_service.pydeps.get_current_userturns every failure of the Cognito lookup into 401deps.py:285-293/meand logout catch onlyCognitoTokenRefusedandValueErrorauth.pyget_user_info,_sign_out_of_cognitoHTTPExceptionto 4401websocket_results._admit_websocket_invite_viewerneed no changeget_current_user;_invite_viewercatchesHTTPExceptionVerification
test_the_cognito_client_has_finite_timeouts,test_the_real_cognito_client_carries_the_configconfig=; a longer connect timeout;max_attemptsin place oftotal_max_attemptstest_a_never_answering_cognito_gives_503_after_two_attempts(127.0.0.1 listener, OS-picked port)ValueErrortest_a_bad_token_stays_401,test_the_classifier_reads_a_hand_built_client_error_without_raisingClientErrorunavailable; readResponseMetadatawith[]test_throttles_and_cognito_server_errors_give_503test_a_cognito_read_timeout_is_not_a_bad_tokenReadTimeoutErrortest_a_refused_token_stays_401_not_503; existingtest_cognito_token_claims.py,test_auth_service.pyand the integrationtest_cognito_token_audience.pyCognitoUnavailable; a refused token answers 503 indeps/me, logout, read scope, WebSocket 4401 (test_cognito_unavailable.py); invite preview (modules/backend/tests/unit/api/test_invite_preview_cognito_unavailable.py)/meclause; drop the logout clause (separately)api-503-keeps-token.test.ts(jest; reads the stored token, no spy onclearToken)/users/meunder a Cognito config leaves the session anonymous, names HTTP 503, keeps the tokensession-check-503-keeps-token.test.tsx(jest)test_the_log_names_the_class_and_code_and_no_tokenRegression tests (
@pytest.mark.regression) fail on the old code:test_the_cognito_client_has_finite_timeouts,test_the_real_cognito_client_carries_the_config,test_a_cognito_read_timeout_is_not_a_bad_tokenandtest_a_never_answering_cognito_gives_503_after_two_attempts. The first two see no Config on the old code, the third a 401 where a 503 belongs, and the last more than two attempts.NOT VERIFIED
🤖 Generated with Claude Code
https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn