-
Notifications
You must be signed in to change notification settings - Fork 17.1k
fix(oauth2): silence lock acquisition errors on token refresh #39463
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
betodealmeida
wants to merge
1
commit into
apache:master
Choose a base branch
from
betodealmeida:oauth2-lock-silence-errors-apache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,6 +338,45 @@ def test_encode_decode_oauth2_state( | |
| assert decoded["user_id"] == 2 | ||
|
|
||
|
|
||
| def test_get_oauth2_access_token_lock_not_acquired_no_error_log( | ||
| mocker: MockerFixture, | ||
| caplog: pytest.LogCaptureFixture, | ||
| ) -> None: | ||
| """ | ||
| Test that when a distributed lock can't be acquired, no error is logged and | ||
| the function returns None instead of raising. | ||
|
|
||
| This scenario occurs when a dashboard with multiple charts from the same | ||
| OAuth2-enabled DB has an expired token: simultaneous requests compete for | ||
| the lock, and only the first one wins. The rest should silently return None. | ||
| """ | ||
| import logging | ||
|
|
||
| from superset.exceptions import AcquireDistributedLockFailedException | ||
|
|
||
| mocker.patch("time.sleep") # avoid backoff delays in tests | ||
|
|
||
| db = mocker.patch("superset.utils.oauth2.db") | ||
| db_engine_spec = mocker.MagicMock() | ||
| token = mocker.MagicMock() | ||
| token.access_token = "access-token" # noqa: S105 | ||
| token.access_token_expiration = datetime(2024, 1, 1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Datetime created without timezone info
Add Code suggestionCheck the AI-generated fix before applying Code Review Run #63dbd9 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||
| token.refresh_token = "refresh-token" # noqa: S105 | ||
| db.session.query().filter_by().one_or_none.return_value = token | ||
|
|
||
| mocker.patch( | ||
| "superset.utils.oauth2.refresh_oauth2_token", | ||
| side_effect=AcquireDistributedLockFailedException("Lock not available"), | ||
| ) | ||
|
|
||
| with freeze_time("2024-01-02"): | ||
| with caplog.at_level(logging.DEBUG): | ||
| result = get_oauth2_access_token({}, 1, 1, db_engine_spec) | ||
|
|
||
| assert result is None | ||
| assert not any(record.levelno >= logging.ERROR for record in caplog.records) | ||
|
|
||
|
|
||
| def test_get_oauth2_redirect_uri_from_config(mocker: MockerFixture) -> None: | ||
| """ | ||
| Test that get_oauth2_redirect_uri returns the configured value when set. | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Setting
raise_on_giveup=Falseswallows allAcquireDistributedLockFailedExceptioncases after retries, including Redis/backend lock failures (not just benign lock contention). That makes real infrastructure errors look like "no token" and can incorrectly trigger fallback auth flows instead of surfacing an operational failure. [logic error]Severity Level: Major⚠️
Steps of Reproduction ✅
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖