From 4bbf1751878b441642f94df69678b57a96b4641f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Jul 2021 12:46:34 +0200 Subject: [PATCH] Fix a crash which can happen when user signs out. The crypto DB has been deleted, and the key download request is cancelled, but in the catch block we tried to write to the deleted DB --- changelog.d/3720.bugfix | 1 + .../android/sdk/internal/crypto/DeviceListManager.kt | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog.d/3720.bugfix diff --git a/changelog.d/3720.bugfix b/changelog.d/3720.bugfix new file mode 100644 index 0000000000..18363b90e3 --- /dev/null +++ b/changelog.d/3720.bugfix @@ -0,0 +1 @@ +Fix a crash which can happen when user signs out \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DeviceListManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DeviceListManager.kt index 63f15aaf6e..79910c6de2 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DeviceListManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DeviceListManager.kt @@ -16,6 +16,7 @@ package org.matrix.android.sdk.internal.crypto +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.launch import org.matrix.android.sdk.api.MatrixPatterns import org.matrix.android.sdk.api.auth.data.Credentials @@ -336,7 +337,12 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM downloadKeysForUsersTask.execute(params) } catch (throwable: Throwable) { Timber.e(throwable, "## CRYPTO | doKeyDownloadForUsers(): error") - onKeysDownloadFailed(filteredUsers) + if (throwable is CancellationException) { + // the crypto module is getting closed, so we cannot access the DB anymore + Timber.w("The crypto module is closed, ignoring this error") + } else { + onKeysDownloadFailed(filteredUsers) + } throw throwable } Timber.v("## CRYPTO | doKeyDownloadForUsers() : Got keys for " + filteredUsers.size + " users")