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

Deadlock and concurrent modification related to Model.data #1944

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

jinliu9508
Copy link
Contributor

@jinliu9508 jinliu9508 commented Dec 15, 2023

Description

One Line Summary

Fix ANR and concurrent modification exception related to Model.setOptAnyProperty that locks Model.data.

Details

Motivation

Fix a bug that causes ANR and/or concurrent modification exception

Scope

This will solve any ANR that calls setOptAnyProperty and concurrent modification exception that calls toJson in the stack trace.

Other

This PR comprises three commits. The first commit introduces a test unit that creates a deadlock scenario, resulting in a failed test due to the deadlock. The second commit implements the fix for the issue, allowing us to observe the successful execution of the unit test post-fix. The third commit concludes with final wrap-up and cleanup, preparing it for merging.

Testing

Unit testing

A test unit is added to SubscriptionManagerTests to simulate a deadlock scenario.

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
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • 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.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

@jinliu9508 jinliu9508 force-pushed the deadlock-between-model-and-subscriber branch from 450d943 to b40fc6b Compare January 2, 2024 20:21
@jinliu9508 jinliu9508 force-pushed the deadlock-between-model-and-subscriber branch 2 times, most recently from 8ebc7ee to 907631b Compare January 2, 2024 21:33
@jinliu9508 jinliu9508 changed the title WIP: Deadlock between model and subscriber Deadlock and concurrent modification related to Model.data Jan 2, 2024
@jinliu9508 jinliu9508 force-pushed the deadlock-between-model-and-subscriber branch from 907631b to 2b7a27b Compare January 2, 2024 22:04
@jinliu9508 jinliu9508 assigned jkasten2 and unassigned jennantilla Jan 2, 2024
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

I see some other possible deadlocks, such as addItem and removeItem since they fire events externally. Even if firing doesn't create a deadlock now this is a risk in the future, as well threads could be waiting longer than needed.

@jinliu9508 jinliu9508 force-pushed the deadlock-between-model-and-subscriber branch from 2b7a27b to 037f81d Compare January 8, 2024 18:58
@jinliu9508 jinliu9508 force-pushed the deadlock-between-model-and-subscriber branch from 037f81d to 4f0d3d1 Compare January 8, 2024 19:20
@jinliu9508 jinliu9508 merged commit 42d19e0 into user-model/main Jan 10, 2024
2 checks passed
@jinliu9508 jinliu9508 deleted the deadlock-between-model-and-subscriber branch January 10, 2024 18:21
@jennantilla jennantilla mentioned this pull request Jan 11, 2024
jinliu9508 added a commit that referenced this pull request Jan 31, 2024
…bscriber

Deadlock and concurrent modification related to Model.data
jinliu9508 added a commit that referenced this pull request Jan 31, 2024
…bscriber

Deadlock and concurrent modification related to Model.data
jinliu9508 added a commit that referenced this pull request Feb 6, 2024
…bscriber

Deadlock and concurrent modification related to Model.data
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