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(amplify): change reset method #866

Merged
merged 6 commits into from
Nov 4, 2020
Merged

fix(amplify): change reset method #866

merged 6 commits into from
Nov 4, 2020

Conversation

ruiguoamz
Copy link
Contributor

@ruiguoamz ruiguoamz commented Nov 3, 2020

Description of changes:

The existing implementation of Amplify.reset() is to call reset() on every Categories and put them in global DispatchGroup which might cause a race condition. For example, during the DataStore reset process, it depends on Hub to dispatch some event, but at that point, Hub might already been reset and cause a precondition failure on https://github.com/aws-amplify/amplify-ios/blob/main/Amplify/Categories/Hub/HubCategory.swift#L44

The change I made is:
reset() on logging and hub categories should be called when other categories finish resetting.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ruiguoamz ruiguoamz self-assigned this Nov 3, 2020
Copy link
Contributor

@diegocstn diegocstn left a comment

Choose a reason for hiding this comment

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

can we maybe use the partition(by:) method to get a partitioned array with .logging and .hub cases at the end?

@@ -22,7 +22,12 @@ extension Amplify {

let group = DispatchGroup()

for categoryType in CategoryType.allCases {
let manuallyResetCategories = [CategoryType.logging, .hub]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let manuallyResetCategories: [CategoryType] = [.logging, .hub]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Synced offline. You can take a look again.

Comment on lines 39 to 41
case .hub, .logging:
// should be waited until other finish resetting
break
Copy link
Contributor

Choose a reason for hiding this comment

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

this class has a lot of hard coding logging and hub categories, maybe you can isolate these two categories that you can reuse in the rest of the code, like

let resetLastCategories = [CategoryType.hub, .logging]

then you can filter before line 25 by let resetFirstCategories = CategoryType.allCases.filter { !resetLastCategories.contains($0) }

With this, would you be able to avoid empty switch cases, similar to code like this?

for categoryType in resetFirstCategories {
    reset(categoryType.category, in: group) { group.leave() }
}

group.wait()

for categoryType in resetLastCategories {
    reset(categoryType.category, in: group) { group.leave() }
}
group.wait()


@ruiguoamz ruiguoamz merged commit 582c7dd into main Nov 4, 2020
@ruiguoamz ruiguoamz deleted the amplify/reset branch November 4, 2020 01:32
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