From 956a2f793fafc168f74deb69bb7728d2263dc766 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Sun, 25 Dec 2022 13:20:09 +0100 Subject: [PATCH] fix: Add timeout to sync http call --- lib/src/client.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index db9a8467..71e60283 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1569,10 +1569,11 @@ class Client extends MatrixApi { } dynamic syncError; await _checkSyncFilter(); + timeout ??= const Duration(seconds: 30); final syncRequest = sync( filter: syncFilterId, since: prevBatch, - timeout: timeout?.inMilliseconds ?? 30000, + timeout: timeout.inMilliseconds, setPresence: syncPresence, ).then((v) => Future.value(v)).catchError((e) { syncError = e; @@ -1580,7 +1581,8 @@ class Client extends MatrixApi { }); _currentSyncId = syncRequest.hashCode; onSyncStatus.add(SyncStatusUpdate(SyncStatus.waitingForResponse)); - final syncResp = await syncRequest; + final syncResp = + await syncRequest.timeout(timeout + const Duration(seconds: 10)); onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing)); if (syncResp == null) throw syncError ?? 'Unknown sync error'; if (_currentSyncId != syncRequest.hashCode) {