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

[Bug] Add Dispatch Queues to all executors #1454

Merged
merged 8 commits into from
Jul 1, 2024

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Jun 21, 2024

Description

One Line Summary

Improve synchronization in the remaining executors (Identity, Subscription, User) to prevent concurrent access crashes.

Details

In #1376, a DispatchQueue was added to the Operation Repo and the Property Executor to serialize access to shared data. These two components encounter the most updates and frequent mutations by different threads. Though rare, the other executors can also encounter concurrent access.

The changes for the Operation Repo and Property Executor appear to be mitigating crashes, so we are adding the same to all executors in this PR:

  • Identity Executor
  • Subscription Executor
  • User Executor (for creates, fetches, etc)

Motivation

We received a report of a crash that I believe is due to one of these remaining executors experiencing a concurrent state access / mutation.

Scope

Executors synchronize array access, mutation, and caching through a Dispatch Queue.

Testing

Unit testing

  • Added tests reproducing crashes
    • testSubscriptionExecutorConcurrency - add test to reproduce crash in Subscription Executor
    • testIdentityExecutorConcurrency - add test to reproduce crash in Identity Executor
    • testUserExecutorConcurrency - add test to reproduce crash in User Executor
    • testPropertyExecutorConcurrency - add test to confirm Property Executor does have have concurrency crashes

Manual testing

Unable to reproduce

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

@nan-li nan-li force-pushed the fix/add_dispatch_queues_to_all_executors branch from df63d6f to c6b8bc6 Compare June 24, 2024 17:02
* When testing concurrency, the Mock Client actually was synchronizing the requests, so crashes were not reproducible
* By changing to a concurrent DispatchQueue, this is more reflective of the real Client's behavior
* Add a flag called `fireSuccessForAllRequests` that will fire the success callback for all requests so that they don't need to be manually set up using mock responses beforehand.
* This is useful for tests that want the client to return success but don't need the details of particular requests.
* Synchronize access to the delta queue and request queues
* Add test `testSubscriptionExecutorConcurrency` that reproduced crash that is then fixed by the changes here.
* Synchronize access to the delta queue and request queues
* Add test `testIdentityExecutorConcurrency` that reproduced crash that is then fixed by the changes here.
* Synchronize access to the request queues
* Add test `testUserExecutorConcurrency` that reproduced crash that is then fixed by the changes here.
* Note that concurrent access in this executor should be mitigated already by the executor only sending one request at a time.
* Add test `testPropertyExecutorConcurrency`
@nan-li nan-li force-pushed the fix/add_dispatch_queues_to_all_executors branch from 36b0075 to 86335fa Compare June 24, 2024 22:52
@nan-li nan-li changed the base branch from main to fix/clearing_notifs_when_swiping_notif_center June 24, 2024 22:52
@nan-li nan-li force-pushed the fix/add_dispatch_queues_to_all_executors branch 16 times, most recently from a6b5ed5 to 6dfdfd8 Compare June 25, 2024 22:39
@nan-li
Copy link
Contributor Author

nan-li commented Jun 26, 2024

The core changes are ready for review... I am trying to fix flaky tests here but those can be moved to a different PR.

@nan-li nan-li requested a review from jennantilla June 26, 2024 03:14
* swiftlint error: Type Body Length Violation: Type body should span 350 lines or less excluding comments and whitespace: currently spans 354 lines (type_body_length)
* No logic changes in this commit, only split up executing requests code into an extension
@nan-li nan-li force-pushed the fix/add_dispatch_queues_to_all_executors branch from 6dfdfd8 to 8248762 Compare June 26, 2024 03:23
Base automatically changed from fix/clearing_notifs_when_swiping_notif_center to main June 27, 2024 18:04
@emawby emawby self-assigned this Jun 27, 2024
Copy link
Contributor

@emawby emawby left a comment

Choose a reason for hiding this comment

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

Looks good!

@nan-li nan-li merged commit 70fcfb0 into main Jul 1, 2024
1 of 2 checks passed
@nan-li nan-li deleted the fix/add_dispatch_queues_to_all_executors branch July 1, 2024 16:05
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.

2 participants