Repository navigation
Publish GIDGoogleUser's tokens as immutable snapshots #645
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
w-goog
wants to merge
4
commits into
main
Choose a base branch
from
fix/googleuser-token-snapshot
base: main
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
90e6068
g-orchestrated: Publish GIDGoogleUser's tokens as one immutable atomi…
w-goog 12701ad
Merge branch 'main' into fix/googleuser-token-snapshot
w-goog 028459d
g-orchestrated: Fix typo in refresh snapshot comment
w-goog d2b930a
g-orchestrated: Test: race didChangeState: and use distinct refresh t…
w-goog 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
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
Oops, something went wrong.
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.
I think this lock fully covers the snapshot write, but I want to check something about the refresh path.
-updateWithTokenResponse:authorizationResponse:profileData:was already under@synchronized(self)before this change, so (as I understand it) the writer that actually had no lock is the refresh callback in-refreshTokensIfNeededWithCompletion:. It calls[self.authState updateWithTokenResponse:error:](andupdateWithAuthorizationError:) without holding the lock, and only gets here through-didChangeState:.So the tokens write is now protected, but
OIDAuthStateitself can still change on that unlocked path while this method is building tokens from it (e.g. a sign-in or addScopes update running at the same time as a refresh). That problem existed before this PR, so I don't think it needs to block this one.A couple of thoughts:
Could we mention this in the PR description, or file a follow-up issue, so it's clear the PR makes the token snapshot safe but doesn't make
OIDAuthStatethread-safe?Would it be cheap to wrap the
authStateupdates in the refresh callback in@synchronized(self)as well?-didChangeState:would then re-enter this lock, which is fine since it's recursive. Other code still readsauthStatewithout the lock (grantedScopes,encodeWithCoder:, and the fetcher authorizer), so fully fixing that is probably a follow-up either way.Related to tests: both stress tests drive
-updateWithTokenResponse:authorizationResponse:profileData:, which was already locked. A variant that races-didChangeState:(or[user.authState updateWithTokenResponse:error:]) against reads would cover the path this PR actually changes. Ideally use a different refresh token for each state so a mixed refresh token would be caught too.Happy to take this as a follow-up if you'd prefer to keep this PR focused.
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.
"That problem existed before this PR, so I don't think it needs to block this one." Good catch; I had a follow-up issue drafted, but should have gone ahead & filed it sooner! Will do.
Safety in the refresh path - the locks for that in the follow-up PR, since we split this one ("Replace @synchronized with _authStateLock.") :)
Tests: I added a new test to cover the didChangeState entry, and to make sure the snapshot is consistent. Great shout for using a different token for each state! Unfortunately, this doesn't seem to cover the lock....I tried it with the lock removed, and it still passes under TSan.