From b664640a05c9a491ed3f7a44845cf59ba1a8c34f Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 25 Jun 2021 12:46:36 +0200 Subject: [PATCH] fix: Don't run syncs while the client is being initialized Fixes that a sync could be done / processed while the client was still being initialized (loaded from database). This has lead to multiple bugs, such as the verified status of keys getting lost, notifications that come in during app startup displaying oddly, etc. Additionally, the init lock was released too early; it is now released when the init is actually done. --- lib/src/client.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 44096d57..0946b367 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -889,7 +889,6 @@ class Client extends MatrixApi { _initLock = false; return; } - _initLock = false; encryption?.dispose(); try { @@ -934,6 +933,7 @@ class Client extends MatrixApi { accountData = await database.getAccountData(id); presences.clear(); } + _initLock = false; onLoginStateChanged.add(LoginState.logged); Logs().i( @@ -1032,6 +1032,10 @@ class Client extends MatrixApi { _retryDelay = Future.delayed(Duration(seconds: syncErrorTimeoutSec)); if (!isLogged() || _disposed || _aborted) return null; try { + if (_initLock) { + Logs().d('Running sync while init isn\'t done yet, dropping request'); + return; + } var syncError; await _checkSyncFilter(); final syncRequest = sync(