Skip to content

chore: make AccountManager concurrency safe - WPB-23570#4340

Open
samwyndham wants to merge 8 commits intodevelopfrom
chore/concurrency-safe-account-manager-WPB-23570
Open

chore: make AccountManager concurrency safe - WPB-23570#4340
samwyndham wants to merge 8 commits intodevelopfrom
chore/concurrency-safe-account-manager-WPB-23570

Conversation

@samwyndham
Copy link
Contributor

@samwyndham samwyndham commented Feb 20, 2026

TaskWPB-23570 [iOS] Make `AccountManager` thread safe

Issue

This PR makes AccountManager, AccountStore & Account Sendable and therefore thread safe. It is part of a larger effort to make Session management safer across concurrent contexts.

I intentionally chose to do this with the aid of locks instead of Actors or @mainactor annotation as:

  • As these types are accessed from many places in nonisolated contexts, marking them as isolated would be a large effort and may lead to bugs.
  • I don't believe there to be performance issues doing this - in fact performance is likely better using locks than using the await keyword.

The negative is there is some additional complexity added to these types themselves.

Note:

I tried to add some tests checking for threading issues but was unsuccessful. I could do it by enabling the thread sanitizer in the test plan and having tests fail on error but there were too many existing tests that would fail in such cases.

Testing

  1. Logging in with multiple account on an older app
  2. Migrating to the new app
  3. There shouldn't be any issues - user should not be logged out.

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

@samwyndham samwyndham marked this pull request as ready for review February 20, 2026 11:32
@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2026

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit a6646e3.

♻️ This comment has been updated with latest results.

Summary: workflow run #22709409675
Allure report (download zip): html-report-28304-chore_concurrency-safe-account-manager-WPB-23570

@datadog-wireapp
Copy link

datadog-wireapp bot commented Feb 20, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 22d7eaf | Docs | Was this helpful? Give us feedback!

/// such as the accounts users name,
/// team name if there is any, picture and uuid.
public final class Account: NSObject, Codable {
public final class Account: NSObject, Codable, @unchecked Sendable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: add a comment explaining why @unchecked Sendable is ok here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 22d7eaf

loginCredentials = account.loginCredentials
handle = account.handle
backendName = account.backendName
lock.withLock {
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: I'm wondering if it's feasible to make Account a immutable structure and to modify this method to return a mutated copy:

public func updateWith(_ account: Account) -> Account {
  guard userIdentifier == account.userIdentifier else { return 
  return Account(
    userIdentifier: userIdentifier,
    userName: account.userName,
    teamName: account.teamName ?? self.teamName,
    ...
  )
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johnxnguyen It will require wider changes because Account is relied upon to be a reference type - E.g. it is expected to be mutated in one place and those mutations to be relied upon in another place.

@samwyndham samwyndham requested review from johnxnguyen and jullianm and removed request for David-Henner March 4, 2026 14:12
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2026

Copy link
Contributor

@jullianm jullianm left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

3 participants