#1562

@unchecked Sendable on KeychainInstallAccessGate suppresses compiler checks without proving safety

Openadwaitm1301opened 3mo ago

bitchat (permissionlesstech/bitchat)

Issue: KeychainInstallAccessGate @unchecked Sendable could cause concurrency issues

Hi team! I was reviewing the keychain code and found that KeychainInstallAccessGate in bitchat/Services/KeychainManager.swift uses @unchecked Sendable with an NSLock. The reconcile closure runs outside the lock, which means the flag check and the reconcile operation are not atomic. If two threads hit this at the same time during install lifecycle reconciliation, you could get duplicate reconcile calls or stale state.

This is on the critical path since it gates ALL keychain access.

A clean fix would be to replace NSLock with OSAllocatedUnfairLock (iOS 16+) which is Sendable-safe, or to wrap the entire reconcile flow inside the lock scope.

PR: Fix KeychainInstallAccessGate Sendable safety

The fix moves the reconcile logic inside the lock scope and replaces NSLock with a proper OSAllocatedUnfairLock. Since the minimum deployment target already supports it, this is a straightforward swap.

The key change is wrapping both the flag check AND the reconcile call in a single lock acquisition so the operation stays atomic across threads.

Activity

0

No activity yet.