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

Feature/frem/check bearer token #138

Merged
merged 2 commits into from
Feb 13, 2022
Merged

Conversation

fremartini
Copy link
Member

closing #68

  • Upon 401 from API app tries to get a new token with credentials from secure storage
  • User is signed out if sufficient amount of retries has been attempted

@fremartini fremartini force-pushed the feature/frem/checkBearerToken branch 3 times, most recently from 4bfaba3 to 4f0d98f Compare February 13, 2022 14:17
@marfavi marfavi enabled auto-merge (squash) February 13, 2022 14:24
@codecov
Copy link

codecov bot commented Feb 13, 2022

Codecov Report

Merging #138 (e01b29d) into develop (1c359b7) will decrease coverage by 3.78%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #138      +/-   ##
===========================================
- Coverage    20.00%   16.21%   -3.79%     
===========================================
  Files            3        3              
  Lines           30       37       +7     
===========================================
  Hits             6        6              
- Misses          24       31       +7     
Flag Coverage Δ
unittests 16.21% <0.00%> (-3.79%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/data/storage/secure_storage.dart 0.00% <0.00%> (ø)

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 1c359b7...e01b29d. Read the comment docs.

@marfavi marfavi merged commit 990f163 into develop Feb 13, 2022
Copy link
Member

@marfavi marfavi left a comment

Choose a reason for hiding this comment

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

🎄

@marfavi marfavi deleted the feature/frem/checkBearerToken branch February 13, 2022 14:29
Copy link
Member

@jonasanker jonasanker left a comment

Choose a reason for hiding this comment

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

@fremartini (Cc @marfavi ) I'm "reopening" the discussion of this implementation as I think there are some design questions which I am unsure has been addressed or have been taken into consideration in the code review :).

Just correct me if my assumptions are wrong 😊 . Let's discuss the question in the comments and see if issues needs to be created :)

lib/utils/reactivation_authenticator.dart Show resolved Hide resolved
lib/utils/reactivation_authenticator.dart Show resolved Hide resolved
import 'package:coffeecard/data/storage/secure_storage.dart';
import 'package:coffeecard/service_locator.dart';

class ReactivationAuthenticator extends Authenticator {
Copy link
Member

Choose a reason for hiding this comment

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

Open question: Have you considered the thread-safety of this class?

I know @TTA777 has introduced parallelism of REST calls which might lead to a scenario where multiple threads end in the authenticator class. This might cause a scenario where read/writes are not visible to the two threads (I think 🤔 )

Copy link
Member

Choose a reason for hiding this comment

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

So I just tried to find out if secure_storage is intended to be thread safe, and it would appear so. According to this issue only versions before 3.3.5 should have issues, and we are on 5.0.2. With that said, there exists an open issue on secure_storage where it might be unable to read from storage, if the user restored the app from a backup. So it might be prudent to at least wrap our calls to the storage in a try catch as suggested in that issue

Copy link
Member

Choose a reason for hiding this comment

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

My concern is both the secure storage but more the fields (retry count and denounce) since these are not visible across threads (if we have a thread issue, that's is).

Copy link
Member Author

Choose a reason for hiding this comment

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

there can arise problems when the two calls on the receiptsPage both return 401 where two attempts to refresh the token are made. I have made some changes here (https://github.com/AnalogIO/coffeecard_app/tree/fix/frem/checkBearerToken) that attempt to address this issue

Copy link
Member

@jonasanker jonasanker Feb 14, 2022

Choose a reason for hiding this comment

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

I assume you are thinking of the static fields you have introduced in the ReactivationAuthenticator?

I understand why you came up with the idea but it would actually provide more unwanted side effects. First, static does not guarantee memory visibility across threads (at least in Java).
Also and maybe more importantly, the Shiftplanning API also uses an Authenticator. Introducing static fields would share the retry count and debouncer between both APIs. We don't want that!

That was a little thread safety rant, sorry 😅

I want to bring some good news though. I have tried reading up on the Dart concurrency model. Dart runs single threaded by standard in what is called an isolate (memory is isolated and not shared). My understanding is that unless you explicitly create several isolate to make multi threaded code, the code will always be single threaded.

My first thought is therefore that we don't have a thread issue here and no risk of dirty read/writes.

Do you agree on my understanding? @fremartini @TTA777

Links

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants