Skip to content

Commit 91a7435

Browse files
committed
Avoid deadlock by moving updating of watchDependenciesSynchronizer outside of the sync queue
1 parent 2de8743 commit 91a7435

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

WooCommerce/Classes/System/SessionManager.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ final class SessionManager: SessionManagerProtocol {
8585
}
8686
}
8787
set {
88-
credentialsQueue.sync {
88+
let shouldUpdateWatchSync = credentialsQueue.sync { () -> Bool in
8989
let currentCredentials = loadCredentials()
9090
guard newValue != currentCredentials else {
91-
return
91+
return false
9292
}
9393

9494
removeCredentials()
@@ -97,6 +97,12 @@ final class SessionManager: SessionManagerProtocol {
9797
saveCredentials(credentials)
9898
}
9999

100+
return true
101+
}
102+
103+
// Update watch synchronizer outside the sync block to avoid potential deadlocks
104+
// from @Published property triggering Combine subscribers that might read credentials
105+
if shouldUpdateWatchSync {
100106
watchDependenciesSynchronizer.credentials = newValue
101107
}
102108
}

0 commit comments

Comments
 (0)