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: Perform optimistic updates without awaiting #548

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

jellybeansoup
Copy link
Contributor

Issue #, if available:
Within the SEEK application, there are occasions where performing a mutation's optimistic update would cause the main thread to lock up for long enough that our crash analytics considers it a hang (typically a couple of seconds), thereby crashing the application.

It's hard to determine an exact cause for this, and it's not at all helped by how rare the issue is. My educated guess is that something is attempting to come back to the main thread as part of performing the optimistic update, potentially within the SQLite layer that I don't have a lot of visibility into. Alternatively, it's possible that there is something like a file system delay that causes SQLite to wait for the file to be unlocked. Regardless, this means that performing a mutation on the main thread (fairly common in scenarios initiated by user interaction) mean that the main thread is locked, as Promise.await() is called synchronously, and thus a semaphore is created.

The resulting stacktrace (truncated to the relevant parts) looks something like this:

  1. Promise.swift, line 106
  2. AWSAppSyncClient.swift, line 293

Description of changes:
In attempting to preserve the public ABI, I've opted to move the optimistic update into the mutation queue, and have removed a reliance upon the await() method. This allows the mutation operation to be created (so it may be returned as Cancellable), while ensuring it isn't actually added to the queue until after the optimistic update is performed.

This allows the method to perform a mutation to return as quickly as possible, and avoids blocking the main thread.

Please note: I have not been able to successfully run integration tests (similar to past contributions), however we have validated that the issue is resolved by shipping the SEEK app using a fork with this change in place, and can confirm that the issue is eradicated.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jellybeansoup jellybeansoup requested a review from a team as a code owner August 15, 2022 04:13
Copy link
Contributor

@royjit royjit left a comment

Choose a reason for hiding this comment

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

LGTM

@harsh62 harsh62 merged commit dad9874 into awslabs:main Jan 16, 2024
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