Skip to content

chore: add some concurrency safety to SessionManager state - WPB-23571#4400

Open
samwyndham wants to merge 31 commits intodevelopfrom
chore/concurrency-safe-session-manager-state-WPB-23571
Open

chore: add some concurrency safety to SessionManager state - WPB-23571#4400
samwyndham wants to merge 31 commits intodevelopfrom
chore/concurrency-safe-session-manager-state-WPB-23571

Conversation

@samwyndham
Copy link
Copy Markdown
Contributor

@samwyndham samwyndham commented Mar 5, 2026

TaskWPB-23571 [iOS] Make `SessionManager` state thread safe

Issue

With this PR I'm trying to add some concurrency safety around updating state in the session manager. I was quite optimistic before starting it but it has become a bit of a struggle. The ideal would be that SessionManager is an Actor but this doesn't feel achievable in the short term. I had hoped to perhaps mark some properties as @MainActor but I don't think this is possible as it looks like much of this state might be accessed from various threads/queues. So in this PR I:

  • Attempt to protect access to activeUserSession, backgroundUserSessions & unauthenticatedSession using an OSAllocatedUnfairLock.
  • In a limited number of places ensure multiple access is done in the same withLockUnchecked call. I've been careful in these cases to avoid calling out to other methods to avoid possible deadlocks.
  • Marked a bunch of methods as @mainactor in AppRouteRouter that I know to be call only from @mainactor.

As you can see this code all gets additionally complex when we try to bring thread safety into it.

Testing

No specific test steps. Instead:

  • Exploritory testing with multiple accounts
  • Regression suite.

Checklist

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

…ger:appStateCalculator:trackingManager:) as @mainactor and some of it's method calls
…ly used.

Also clean up init of ProxyCredentials
@samwyndham samwyndham force-pushed the chore/concurrency-safe-session-manager-state-WPB-23571 branch from 7dbc3f5 to 6ab1bb1 Compare March 5, 2026 09:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Test Results

    3 files    463 suites   3m 32s ⏱️
3 439 tests 3 411 ✅ 27 💤 1 ❌
3 439 runs  3 412 ✅ 27 💤 0 ❌

For more details on these failures, see this check.

Results for commit 0079317.

♻️ This comment has been updated with latest results.

Summary: workflow run #23639896422
Allure report (download zip): html-report-28847-chore_concurrency-safe-session-manager-state-WPB-23571

+ account.userIdentifier.safeForLoggingDescription
)

delegate?.sessionManagerDidChangeActiveUserSession(userSession: session)
Copy link
Copy Markdown
Contributor Author

@samwyndham samwyndham Mar 5, 2026

Choose a reason for hiding this comment

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

This is a no-op so deleting the delegate method altogether

Base automatically changed from chore/concurrency-safe-account-manager-WPB-23570 to develop March 16, 2026 11:30
…ate-WPB-23571

# Conflicts:
#	wire-ios-sync-engine/Source/SessionManager/SessionManager.swift
@datadog-wireapp
Copy link
Copy Markdown

datadog-wireapp bot commented Mar 25, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

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

@samwyndham samwyndham closed this Mar 25, 2026
@samwyndham samwyndham reopened this Mar 25, 2026
@samwyndham samwyndham closed this Mar 25, 2026
@samwyndham samwyndham reopened this Mar 25, 2026
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@David-Henner David-Henner left a comment

Choose a reason for hiding this comment

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

Nice work! Were there a lot of issues related to concurrency in the SessionManager before ?

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