From 51fed9e59356f937110e17f2c3b4b06555e65e3d Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 31 Aug 2025 14:22:08 -0700 Subject: [PATCH] Fix potential timing bug (#649) --- .../Packages/Sources/SecretAgentKit/SocketController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Packages/Sources/SecretAgentKit/SocketController.swift b/Sources/Packages/Sources/SecretAgentKit/SocketController.swift index 0f592a0..19b040a 100644 --- a/Sources/Packages/Sources/SecretAgentKit/SocketController.swift +++ b/Sources/Packages/Sources/SecretAgentKit/SocketController.swift @@ -78,7 +78,6 @@ extension SocketController { provenance = SigningRequestTracer().provenance(from: fileHandle) (messages, messagesContinuation) = AsyncStream.makeStream() Task { [messagesContinuation, logger] in - await fileHandle.waitForDataInBackgroundAndNotifyOnMainActor() for await _ in NotificationCenter.default.notifications(named: .NSFileHandleDataAvailable, object: fileHandle) { let data = fileHandle.availableData guard !data.isEmpty else { @@ -91,6 +90,9 @@ extension SocketController { logger.debug("Socket controller yielded data.") } } + Task { + await fileHandle.waitForDataInBackgroundAndNotifyOnMainActor() + } } /// Writes new data to the socket.