Merge pull request #1893 from famedly/krille/no-timeout-for-initial-sync

refactor: Do not set default timeout for initialSync
This commit is contained in:
Krille-chan 2024-12-02 10:51:36 +01:00 committed by GitHub
commit 67a95e3973
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 7 deletions

View File

@ -2283,16 +2283,18 @@ class Client extends MatrixApi {
// The timeout we send to the server for the sync loop. It says to the
// server that we want to receive an empty sync response after this
// amount of time if nothing happens.
timeout ??= const Duration(seconds: 30);
if (prevBatch != null) timeout ??= const Duration(seconds: 30);
await ensureNotSoftLoggedOut(timeout * 2);
await ensureNotSoftLoggedOut(
timeout == null ? const Duration(minutes: 1) : (timeout * 2),
);
await _checkSyncFilter();
final syncRequest = sync(
filter: syncFilterId,
since: prevBatch,
timeout: timeout.inMilliseconds,
timeout: timeout?.inMilliseconds,
setPresence: syncPresence,
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
if (e is MatrixException) {
@ -2308,11 +2310,13 @@ class Client extends MatrixApi {
// The timeout for the response from the server. If we do not set a sync
// timeout (for initial sync) we give the server a longer time to
// responde.
final responseTimeout = timeout == Duration.zero
? const Duration(minutes: 2)
: timeout + const Duration(seconds: 10);
final responseTimeout =
timeout == null ? null : timeout + const Duration(seconds: 10);
final syncResp = responseTimeout == null
? await syncRequest
: await syncRequest.timeout(responseTimeout);
final syncResp = await syncRequest.timeout(responseTimeout);
onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing));
if (syncResp == null) throw syncError ?? 'Unknown sync error';
if (_currentSyncId != syncRequest.hashCode) {