Skip to content
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

fix(oauth): add locking to prevent race conditions in grant exchange #85570

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mdtro
Copy link
Member

@mdtro mdtro commented Feb 20, 2025

Pulled from #82052 to break out these changes into smaller PRs.

Use locks to ensure an ApiGrant cannot be used twice during a race condition that would result in multiple access/refresh token pairs.

…xchanges

- Add InvalidGrantError and ExpiredGrantError
- Add get_lock_key method to ApiGrant
- Add locking around grant exchanges in ApiToken.from_grant
- Add tests for race conditions
- add application status check in grant validation
- better error handling for lock acquisition failures
- add tests for concurrent grant usage
@mdtro mdtro requested review from a team as code owners February 20, 2025 19:22
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 20, 2025
Copy link

codecov bot commented Feb 20, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
23595 1 23594 290
View the top 1 failed test(s) by shortest run time
tests.sentry.sentry_apps.token_exchange.test_grant_exchanger.TestGrantExchanger::test_race_condition_on_grant_exchange
Stack Traces | 2.66s run time
#x1B[1m#x1B[.../sentry_apps/token_exchange/test_grant_exchanger.py#x1B[0m:120: in test_race_condition_on_grant_exchange
    with pytest.raises(UnableToAcquireLock):
#x1B[1m#x1B[31mE   Failed: DID NOT RAISE <class 'sentry.utils.locking.UnableToAcquireLock'>#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant