Try mitigating unexpected logouts (#2251)

* Try mitigating unexpected logouts.

Try making getting/storing session data use a Mutex for synchronization.

Also added some more logs so we can understand exactly where it's failing.
This commit is contained in:
Jorge Martin Espinosa 2024-01-18 16:22:25 +01:00 committed by GitHub
parent e00d1abe44
commit 6ecce81f45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 15 deletions

View file

@ -139,6 +139,8 @@ class RustMatrixClient(
// TODO handle isSoftLogout parameter.
appCoroutineScope.launch {
val existingData = sessionStore.getSession(client.userId())
val anonymizedToken = existingData?.accessToken?.takeLast(4)
Timber.d("Removing session data with token: '...$anonymizedToken'.")
if (existingData != null) {
// Set isTokenValid to false
val newData = client.session().toSessionData(
@ -146,8 +148,15 @@ class RustMatrixClient(
loginType = existingData.loginType,
)
sessionStore.updateData(newData)
Timber.d("Removed session data with token: '...$anonymizedToken'.")
} else {
Timber.d("No session data found.")
}
doLogout(doRequest = false, removeSession = false, ignoreSdkError = false)
}.invokeOnCompletion {
if (it != null) {
Timber.e(it, "Failed to remove session data.")
}
}
} else {
Timber.v("didReceiveAuthError -> already cleaning up")
@ -158,11 +167,18 @@ class RustMatrixClient(
Timber.w("didRefreshTokens()")
appCoroutineScope.launch {
val existingData = sessionStore.getSession(client.userId()) ?: return@launch
val anonymizedToken = client.session().accessToken.takeLast(4)
Timber.d("Saving new session data with token: '...$anonymizedToken'. Was token valid: ${existingData.isTokenValid}")
val newData = client.session().toSessionData(
isTokenValid = existingData.isTokenValid,
isTokenValid = true,
loginType = existingData.loginType,
)
sessionStore.updateData(newData)
Timber.d("Saved new session data with token: '...$anonymizedToken'.")
}.invokeOnCompletion {
if (it != null) {
Timber.e(it, "Failed to save new session data.")
}
}
}
}