[PR #2434] [MERGED] [PM-1576] Fix Race condition AccountsManager registration #3564

Closed
opened 2025-11-26 23:34:28 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/bitwarden/android/pull/2434
Author: @fedemkr
Created: 3/23/2023
Status: Merged
Merged: 4/7/2023
Merged by: @trmartin4

Base: masterHead: PM-1576-race-condition-accountsmanager-registration


📝 Commits (6)

  • 72247a9 PM-1576 Moved registration of AccountsManager to avoid race conditions with the app start. To do so, added ConditionedAwaiterManager so that it handles a task to be awaited or completed depending on the callers.
  • 59d223f Merge branch 'master' into PM-1576-race-condition-accountsmanager-registration
  • 1e37b68 PM-1576 Fix format
  • a98442a Merge branch 'master' into PM-1576-race-condition-accountsmanager-registration
  • 801d800 Merge branch 'master' into PM-1576-race-condition-accountsmanager-registration
  • 7705a6b PM-1576 Fix throw to preserve StackTrace

📊 Changes

7 files changed (+131 additions, -36 deletions)

View changed files

📝 src/Android/MainApplication.cs (+2 -1)
📝 src/App/Utilities/AccountManagement/AccountsManager.cs (+14 -1)
src/Core/Abstractions/IConditionedAwaiterManager.cs (+17 -0)
src/Core/Services/ConditionedAwaiterManager.cs (+42 -0)
📝 src/Core/Services/EnvironmentService.cs (+39 -21)
📝 src/Core/Utilities/ServiceContainer.cs (+3 -1)
📝 src/iOS.Core/Utilities/iOSCoreHelpers.cs (+14 -12)

📄 Description

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

There are some cases where a race-condition happens on AccountsManager registration and it ends up crashing the iOS app.

Code changes

  • ConditionedAwaiterManager: Added this class as a helper to have a condition task that can be awaited and can be completed/faulted from other services without needing any dependencies. This uses the AwaiterPrecondition to handle the proper task depending on the condition.
  • AccountsManager: It now awaits for the precondition EnvironmentUrlsInited in order to perform any calls which is why before was being registered too late and now it can be registered before the App.App constructor is called.
  • EnvironmentService: Change to update the ConditionedAwaiterManager -> EnvironmentUrlsInited precondition accordingly depending if it succeeds or fails.
  • ServiceContainer: Moved the registration of the AccountsManager to be in a sooner place so that race-condition don't happen with the start of the application

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/bitwarden/android/pull/2434 **Author:** [@fedemkr](https://github.com/fedemkr) **Created:** 3/23/2023 **Status:** ✅ Merged **Merged:** 4/7/2023 **Merged by:** [@trmartin4](https://github.com/trmartin4) **Base:** `master` ← **Head:** `PM-1576-race-condition-accountsmanager-registration` --- ### 📝 Commits (6) - [`72247a9`](https://github.com/bitwarden/android/commit/72247a910265477b373e08027b2b7661976e96ce) PM-1576 Moved registration of AccountsManager to avoid race conditions with the app start. To do so, added ConditionedAwaiterManager so that it handles a task to be awaited or completed depending on the callers. - [`59d223f`](https://github.com/bitwarden/android/commit/59d223f573389b085309fda40ec7728a74ee8645) Merge branch 'master' into PM-1576-race-condition-accountsmanager-registration - [`1e37b68`](https://github.com/bitwarden/android/commit/1e37b68c68e1a0c9229599d2e39cb32513ebb359) PM-1576 Fix format - [`a98442a`](https://github.com/bitwarden/android/commit/a98442a6172a598b21d2ecef1a315710dd37288a) Merge branch 'master' into PM-1576-race-condition-accountsmanager-registration - [`801d800`](https://github.com/bitwarden/android/commit/801d8002cd590eaf353889eddbfdbc19b301c6c3) Merge branch 'master' into PM-1576-race-condition-accountsmanager-registration - [`7705a6b`](https://github.com/bitwarden/android/commit/7705a6b8f11c96becaea784905d1a22be84e645a) PM-1576 Fix throw to preserve StackTrace ### 📊 Changes **7 files changed** (+131 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `src/Android/MainApplication.cs` (+2 -1) 📝 `src/App/Utilities/AccountManagement/AccountsManager.cs` (+14 -1) ➕ `src/Core/Abstractions/IConditionedAwaiterManager.cs` (+17 -0) ➕ `src/Core/Services/ConditionedAwaiterManager.cs` (+42 -0) 📝 `src/Core/Services/EnvironmentService.cs` (+39 -21) 📝 `src/Core/Utilities/ServiceContainer.cs` (+3 -1) 📝 `src/iOS.Core/Utilities/iOSCoreHelpers.cs` (+14 -12) </details> ### 📄 Description ## Type of change - [X] Bug fix - [ ] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ## Objective <!--Describe what the purpose of this PR is. For example: what bug you're fixing or what new feature you're adding--> There are some cases where a race-condition happens on `AccountsManager` registration and it ends up crashing the iOS app. ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> * **ConditionedAwaiterManager:** Added this class as a helper to have a condition task that can be awaited and can be completed/faulted from other services without needing any dependencies. This uses the `AwaiterPrecondition` to handle the proper task depending on the condition. * **AccountsManager:** It now awaits for the precondition `EnvironmentUrlsInited` in order to perform any calls which is why before was being registered too late and now it can be registered before the App.App constructor is called. * **EnvironmentService:** Change to update the `ConditionedAwaiterManager` -> `EnvironmentUrlsInited` precondition accordingly depending if it succeeds or fails. * **ServiceContainer:** Moved the registration of the `AccountsManager` to be in a sooner place so that race-condition don't happen with the start of the application ## Before you submit - Please check for formatting errors (`dotnet format --verify-no-changes`) (required) - Please add **unit tests** where it makes sense to do so (encouraged but not required) - If this change requires a **documentation update** - notify the documentation team - If this change has particular **deployment requirements** - notify the DevOps team --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-26 23:34:28 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/android#3564