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

lastSyncTime is not being used (sometimes) #232

Closed
airstance opened this issue Apr 12, 2019 · 3 comments
Closed

lastSyncTime is not being used (sometimes) #232

airstance opened this issue Apr 12, 2019 · 3 comments
Assignees
Labels
bug Something isn't working closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made.

Comments

@airstance
Copy link

Describe the bug
There are times when the delta sync code does not use the correct lastSyncTime

To Reproduce
Steps to reproduce the behavior:

  1. Start a sync operation with a delta sync query
  2. Perform at least one sync from the server so that lastSyncTime is set
  3. Force a new sync operation (rerun application, foreground switch, network toggle)
  4. There are times when the lastSyncTime isn't fetched from the cache correctly. It will look somewhat random.

Expected behavior
The lastSyncTime should be the same value as the last successful delta/base sync

Environment(please complete the following information):

  • AppSync SDK Version: 2.10.3
  • Dependency Manager: Cocoapods
  • Swift Version : 4.2+

Additional context
There's a bug in AppSyncSubscriptionWithSync.getOperationHash(). The code uses the description of dictionaries which have no order and can randomly return different string values.

Here's a fix that first sorts the dictionary into an array.

    private func getOperationHash() -> String {
        
        var baseString = ""
        
        let variables = baseQuery.variables?.sorted(by: { $0.0 < $1.0 }).description ?? ""
        baseString = type(of: baseQuery).requestString + variables

        if let subscription = subscription {
            let variables = subscription.variables?.sorted(by: { $0.0 < $1.0 }).description ?? ""
            baseString = type(of: subscription).requestString + variables
        }
        
        if let deltaQuery = deltaQuery {
            let variables = deltaQuery.variables?.sorted(by: { $0.0 < $1.0 }).description ?? ""
            baseString = type(of: deltaQuery).requestString + variables
        }
        AppSyncLog.debug("Creating hash for \(baseString)")
        return AWSSignatureSignerUtility.hash(baseString.data(using: .utf8)!)!.base64EncodedString()
    }

This was the issue that was causing me trouble with #219

These bugs are very time consuming to find and fix.

@palpatim palpatim added AppSync bug Something isn't working labels Apr 15, 2019
@rohandubal
Copy link
Contributor

Thanks for the detailed information @airstance

I am working to reproduce this on my side.

@rohandubal rohandubal added the pending investigation It has been triaged and discussed but the actual work is still pending label Apr 18, 2019
@royjit royjit assigned royjit and unassigned rohandubal Jun 13, 2019
@palpatim palpatim added pending-release Work is done, but issue can't be closed since the changes were not released yet and removed pending investigation It has been triaged and discussed but the actual work is still pending labels Jun 27, 2019
@royjit
Copy link
Contributor

royjit commented Jul 9, 2019

This fix has been released in the version 2.14.0

@royjit royjit added closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made. and removed pending-release Work is done, but issue can't be closed since the changes were not released yet labels Jul 9, 2019
@stale stale bot removed the closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made. label Jul 9, 2019
@royjit royjit added the closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made. label Jul 9, 2019
@stale
Copy link

stale bot commented Jul 16, 2019

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closing-soon-if-no-response This issue will be closed in 7 days unless further comments are made.
Projects
None yet
Development

No branches or pull requests

4 participants