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:
parent
e00d1abe44
commit
6ecce81f45
3 changed files with 45 additions and 15 deletions
|
|
@ -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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue