From fbade40e66d9d4396bfa5c5edbdc140832e16030 Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 17 Oct 2025 08:50:44 -0700 Subject: [PATCH] fix(apple): don't return Data() to fetchResources (#10605) When the tunnel first comes up, the first call to `fetchResources` was returning an empty `Data()` instance that the receiver would fail to decode properly because it assumes if a `Data` is non-nil, it is a list of Resources. This resulted in a decode error each time the tunnel was started. Related: https://github.com/firezone/firezone/pull/10603#discussion_r2438472011 --------- Signed-off-by: Jamil Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../FirezoneNetworkExtension/Adapter.swift | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/swift/apple/FirezoneNetworkExtension/Adapter.swift b/swift/apple/FirezoneNetworkExtension/Adapter.swift index 62ee72ae3..d8aceb94f 100644 --- a/swift/apple/FirezoneNetworkExtension/Adapter.swift +++ b/swift/apple/FirezoneNetworkExtension/Adapter.swift @@ -297,24 +297,22 @@ class Adapter: @unchecked Sendable { guard let self = self else { return } // Convert uniffi resources to FirezoneKit resources and encode with PropertyList - let propertyListData: Data - if let uniffiResources = self.resources { - let firezoneResources = uniffiResources.map { self.convertResource($0) } - guard let encoded = try? PropertyListEncoder().encode(firezoneResources) else { - Log.log("Failed to encode resources as PropertyList") - completionHandler(nil) - return - } - propertyListData = encoded - } else { - propertyListData = Data() + guard let uniffiResources = self.resources + else { return completionHandler(nil) } + + let firezoneResources = uniffiResources.map { self.convertResource($0) } + + guard let encoded = try? PropertyListEncoder().encode(firezoneResources) + else { + Log.log("Failed to encode resources as PropertyList") + return completionHandler(nil) } - if hash == Data(SHA256.hash(data: propertyListData)) { + if hash == Data(SHA256.hash(data: encoded)) { // nothing changed completionHandler(nil) } else { - completionHandler(propertyListData) + completionHandler(encoded) } } }