mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-26 06:49:33 +00:00
fix(mac): document the main-queue serialization and harden the deadlock test cleanup
The lock no longer covers the defaults write, so the main-queue hop is what keeps the read-modify-write atomic; say so where the next reader would be tempted to make it async. The regression test now cleans up its observer and defaults domain on every exit and waits up to 5 seconds, so a loaded runner cannot fake a deadlock.
This commit is contained in:
parent
da20fd0f42
commit
c436787239
2 changed files with 13 additions and 5 deletions
|
|
@ -214,6 +214,12 @@ enum CapacityDockProviderCredentialPresence {
|
|||
object: nil
|
||||
)
|
||||
}
|
||||
// The lock only covers the compute above; releasing it before the
|
||||
// defaults write is what breaks the reentrancy deadlock. What keeps the
|
||||
// read-modify-write atomic across concurrent callers is that every
|
||||
// mutation runs serialized on the main queue, so this must stay a
|
||||
// synchronous hop: switching it to async reintroduces lost updates and
|
||||
// breaks read-after-write (see CredentialKeychainContinuityTests).
|
||||
if Thread.isMainThread {
|
||||
update()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -128,21 +128,23 @@ struct ProviderSettingsEditorStateTests {
|
|||
_ = CapacityDockProviderCredentialPresence.contains("kimi", defaults: defaultsBox.value)
|
||||
callbackFinished.setCompleted()
|
||||
}
|
||||
defer {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
defaults.removePersistentDomain(forName: suiteName)
|
||||
}
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
CapacityDockProviderCredentialPresence.set(true, for: "kimi", defaults: defaultsBox.value)
|
||||
writeFinished.setCompleted()
|
||||
}
|
||||
for _ in 0..<50 where !writeFinished.isCompleted {
|
||||
// A deadlocked write never completes, so the bound only needs to be
|
||||
// generous enough that a loaded CI runner cannot fake one.
|
||||
for _ in 0..<500 where !writeFinished.isCompleted {
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
|
||||
#expect(callbackFinished.isCompleted)
|
||||
#expect(writeFinished.isCompleted)
|
||||
if writeFinished.isCompleted {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
defaults.removePersistentDomain(forName: suiteName)
|
||||
}
|
||||
}
|
||||
|
||||
@Test("credential mutations await their real Keychain completion")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue