From 6851dfbe79c04dd910d294957ee5cae211d69dd3 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Wed, 22 Jan 2025 21:49:27 -0500 Subject: [PATCH] Clear thread-local even if an error is thrown --- Sources/SecureXPC/Server/ClientIdentity.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/SecureXPC/Server/ClientIdentity.swift b/Sources/SecureXPC/Server/ClientIdentity.swift index 7a2c032..1def9d9 100644 --- a/Sources/SecureXPC/Server/ClientIdentity.swift +++ b/Sources/SecureXPC/Server/ClientIdentity.swift @@ -55,10 +55,10 @@ public extension XPCServer { ) rethrows -> R { Thread.current.threadDictionary[contextKey] = XPCServer.ClientIdentity(connection: connection, message: message) - let result = try operation() - Thread.current.threadDictionary.removeObject(forKey: contextKey) + + defer { Thread.current.threadDictionary.removeObject(forKey: contextKey) } - return result + return try operation() } // MARK: current context