Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Closes #5050: Improve handling of authentication problems #5103

Merged
merged 5 commits into from
Nov 20, 2019

Conversation

grigoryk
Copy link
Contributor

@grigoryk grigoryk commented Nov 19, 2019

This PR ensures that account doesn't disappear on app restart after hitting authentication problems.

Also:

  • there's some FxaDeviceConstellation cleanup/simplification
  • profile cache is now used; this way, we don't need to fetch profile every time account manager is instantiated

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@grigoryk grigoryk force-pushed the missingAccountStartup5050 branch from f9600df to 83f6dff Compare November 19, 2019 21:48
@codecov
Copy link

codecov bot commented Nov 19, 2019

Codecov Report

Merging #5103 into master will increase coverage by 0.89%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #5103      +/-   ##
============================================
+ Coverage     80.78%   81.68%   +0.89%     
+ Complexity     4018      391    -3627     
============================================
  Files           515       42     -473     
  Lines         18142     1976   -16166     
  Branches       2633      273    -2360     
============================================
- Hits          14656     1614   -13042     
+ Misses         2417      246    -2171     
+ Partials       1069      116     -953
Impacted Files Coverage Δ Complexity Δ
...wser/search/provider/AssetsSearchEngineProvider.kt 94.68% <0%> (ø) 31% <0%> (ø) ⬇️
...owser/search/suggestions/SearchSuggestionClient.kt 80% <0%> (ø) 6% <0%> (ø) ⬇️
...la/components/browser/search/suggestions/Parser.kt 78.12% <0%> (ø) 0% <0%> (ø) ⬇️
...a/components/browser/search/SearchEngineManager.kt 90.74% <0%> (ø) 24% <0%> (ø) ⬇️
...r/localization/LocaleSearchLocalizationProvider.kt 100% <0%> (ø) 2% <0%> (ø) ⬇️
...la/components/browser/search/SearchEngineParser.kt 73.41% <0%> (ø) 20% <0%> (ø) ⬇️
.../mozilla/components/browser/search/SearchEngine.kt 100% <0%> (ø) 14% <0%> (ø) ⬇️
...search/provider/localization/SearchLocalization.kt 100% <0%> (ø) 5% <0%> (ø) ⬇️
...ts/browser/search/provider/SearchEngineProvider.kt 100% <0%> (ø) 0% <0%> (ø) ⬇️
...wser/toolbar/display/TrackingProtectionIconView.kt
... and 470 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25a0514...767cf4b. Read the comment docs.

Copy link
Contributor

@csadilek csadilek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@grigoryk
Copy link
Contributor Author

There's a bit of a problem with the profile cache - we need to keep profile on account manager populated while in AuthenticationProblems, but underlying APIs don't have a way to force local querying of the cache - we may hit a network, which will hit auth problems. I'll deal with this in a follow-up.

Grisha Kruglov added 5 commits November 19, 2019 16:29
I'm not sure it was ever necessary, to be honest. I think the way the 'refresh'
method is currently structured, simply marking internal 'constellationState'
as Volatile is enough - we're not concerned about concurrent access to it,
only about memory visibility across threads.

It's true that currently, work in this class happens on a pool thread,
so it's possible to have two racing 'refresh' methods running. Having one of them
loose the race and drop results on the floor should be just fine in this case.
Before this patch, we'd clear out account storage after we see an unrecoverable authentication error. In this context, a password change would be an unrecoverable error. We'll transition account into an AuthenticationProblem state, but upon re-initialization of the state machine we'll end up in NotAuthenticated instead, because there's no longer a locally persisted account state. So, this is just a straight-up bug in the state machine.

So, step 1:
    do not erase account storage if we encounter auth problems we can't auto-recover from
        this will make sure account isn't disappearing after a restart
        this has an additional benefit of not erasing fetched profile data, as well! it's part of the persisted account state

Also, add in some debug logging into the samples-sync app to make testing this a bit easier.
…storation

If we don't do this, we end up calling onAuthenticated _after_ callin onAuthenticationProblems.

This isn't a very principled solution, since other similar situations aren't covered.
And, we may fail 'ensureCapabilities' for reasons other than authentication (e.g. network failures).

Arguably, stopping here _is_ better than progressing with an uncertain state.
@grigoryk grigoryk force-pushed the missingAccountStartup5050 branch from 83f6dff to 767cf4b Compare November 20, 2019 00:29
@grigoryk
Copy link
Contributor Author

bors r=csadilek

bors bot pushed a commit that referenced this pull request Nov 20, 2019
5103: Closes #5050: Improve handling of authentication problems r=csadilek a=grigoryk

This PR ensures that account doesn't disappear on app restart after hitting authentication problems.

Also:
- there's some FxaDeviceConstellation cleanup/simplification
- profile cache is now used; this way, we don't need to fetch profile every time account manager is instantiated



Co-authored-by: Grisha Kruglov <[email protected]>
@bors
Copy link

bors bot commented Nov 20, 2019

Build succeeded

  • complete-push

@bors bors bot merged commit 767cf4b into mozilla-mobile:master Nov 20, 2019
@grigoryk grigoryk deleted the missingAccountStartup5050 branch November 20, 2019 02:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants