From ac2fdba3f1a5052000c60e65a67c8cac77863059 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Tue, 21 Apr 2026 17:14:17 +0100 Subject: [PATCH] Fix a potential crash caused by using old Sentry transactions. (#5459) * Fix a deprecation warning. * Remove unused method. * Fix a crash caused by using old Sentry transactions. --- ElementX/Sources/Application/AppCoordinator.swift | 12 ++++++------ ElementX/Sources/Services/Analytics/Signposter.swift | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 282f3e7c1..d660d847d 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -1027,22 +1027,22 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg // This callback is only executed once during the entire run of the program to avoid // multiple callbacks if there are multiple crash events to send (see method documentation) - options.onCrashedLastRun = { event in + options.onLastRunStatusDetermined = { status, event in + guard case .didCrash = status, let event else { return } MXLog.error("Sentry detected a crash in the previous run: \(event.eventId.sentryIdString)") bugReportService.lastCrashEventID = event.eventId.sentryIdString } + // Any ongoing transactions will no longer be valid after calling SentrySDK.start so lets + // remove them and start over, otherwise the app will crash if finishTransaction is used. + ServiceLocator.shared.analytics.signpost.resetTransactions() + SentrySDK.start(options: options) // Swift enableSentryLogging(enabled: options.enabled) // Rust MXLog.info("Sentry configured (enabled: \(options.enabled))") } - private func teardownSentry() { - SentrySDK.close() - MXLog.info("SentrySDK stopped") - } - private func processInlineReply(roomID: String, replyText: String) async { guard let userSession else { fatalError("User session not setup") diff --git a/ElementX/Sources/Services/Analytics/Signposter.swift b/ElementX/Sources/Services/Analytics/Signposter.swift index c92098200..56879b324 100644 --- a/ElementX/Sources/Services/Analytics/Signposter.swift +++ b/ElementX/Sources/Services/Analytics/Signposter.swift @@ -75,6 +75,10 @@ class Signposter { transactions[transactionName] = nil } + func resetTransactions() { + transactions.removeAll() + } + // MARK: - Spans func addSpan(_ spanName: SpanName, toTransaction transactionName: TransactionName) -> Span? {