From 5a4d21ab7a0ad340128d444def099f3459a9cdc4 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:05:48 +0100 Subject: [PATCH] Fix a crash when the ClientProxy is freed. (#3090) --- ElementX/Sources/Services/Client/ClientProxy.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 2e1863c90..845ecf257 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -288,11 +288,14 @@ class ClientProxy: ClientProxyProtocol { restartTask = nil } - Task { + // Capture the sync service strongly as this method is called on deinit and so the + // existence of self when the Task executes is questionable and would sometimes crash. + Task { [syncService] in do { defer { completion?() } + try await syncService?.stop() } catch { MXLog.error("Failed stopping the sync service with error: \(error)")