Add more logging.

This commit is contained in:
Max Goedjen 2025-11-16 19:01:10 -08:00
parent 9216a2b931
commit acc1023cb2
No known key found for this signature in database
3 changed files with 16 additions and 4 deletions

View File

@ -120,7 +120,7 @@ extension Agent {
/// Gives any store with no loaded secrets a chance to reload.
func reloadSecretsIfNeccessary() async {
for store in await storeList.stores {
if await store.secrets.isEmpty {
if await store.isAvailable, await store.secrets.isEmpty {
let name = await store.name
logger.debug("Store \(name, privacy: .public) has no loaded secrets. Reloading.")
await store.reloadSecrets()

View File

@ -36,7 +36,7 @@ extension SigningRequestTracer {
/// - Parameter pid: The process ID to look up.
/// - Returns: A ``SecretKit.SigningRequestProvenance.Process`` describing the process.
func process(from pid: Int32) -> SigningRequestProvenance.Process {
var pidAndNameInfo = self.pidAndNameInfo(from: pid)
var pidAndNameInfo = unsafe self.pidAndNameInfo(from: pid)
let ppid = unsafe pidAndNameInfo.kp_eproc.e_ppid != 0 ? pidAndNameInfo.kp_eproc.e_ppid : nil
let procName = unsafe withUnsafeMutablePointer(to: &pidAndNameInfo.kp_proc.p_comm.0) { pointer in
unsafe String(cString: pointer)

View File

@ -37,12 +37,19 @@ public struct SocketController {
port = SocketPort(path: path)
fileHandle = FileHandle(fileDescriptor: port.socket, closeOnDealloc: true)
Task { [fileHandle, sessionsContinuation, logger] in
logger.debug("Starting socket controller task")
for await notification in NotificationCenter.default.notifications(named: .NSFileHandleConnectionAccepted) {
logger.debug("Socket controller accepted connection")
guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else { continue }
guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else {
logger.error("FileHandle not present in user info.")
continue
}
let session = Session(fileHandle: new)
logger.debug("Yielding session")
sessionsContinuation.yield(session)
logger.debug("Yielded session")
await fileHandle.acceptConnectionInBackgroundAndNotifyOnMainActor()
logger.debug("Session waiting for connection.")
}
}
fileHandle.acceptConnectionInBackgroundAndNotify(forModes: [RunLoop.Mode.common])
@ -74,11 +81,15 @@ extension SocketController {
/// Initializes a new Session.
/// - Parameter fileHandle: The FileHandle used to communicate with the socket.
init(fileHandle: FileHandle) {
logger.debug("Initializing session.")
self.fileHandle = fileHandle
provenance = SigningRequestTracer().provenance(from: fileHandle)
logger.debug("Traced provenance.")
(messages, messagesContinuation) = AsyncStream.makeStream()
Task { [messagesContinuation, logger] in
logger.debug("Starting Session task.")
for await _ in NotificationCenter.default.notifications(named: .NSFileHandleDataAvailable, object: fileHandle) {
logger.debug("Session received data avilable message.")
let data = fileHandle.availableData
guard !data.isEmpty else {
logger.debug("Socket controller received empty data, ending continuation.")
@ -90,7 +101,8 @@ extension SocketController {
logger.debug("Socket controller yielded data.")
}
}
Task {
Task { [logger] in
logger.debug("Session waiting for data.")
await fileHandle.waitForDataInBackgroundAndNotifyOnMainActor()
}
}