fix: Add timeout to sync http call
This commit is contained in:
parent
7a5b013c92
commit
956a2f793f
|
|
@ -1569,10 +1569,11 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
dynamic syncError;
|
dynamic syncError;
|
||||||
await _checkSyncFilter();
|
await _checkSyncFilter();
|
||||||
|
timeout ??= const Duration(seconds: 30);
|
||||||
final syncRequest = sync(
|
final syncRequest = sync(
|
||||||
filter: syncFilterId,
|
filter: syncFilterId,
|
||||||
since: prevBatch,
|
since: prevBatch,
|
||||||
timeout: timeout?.inMilliseconds ?? 30000,
|
timeout: timeout.inMilliseconds,
|
||||||
setPresence: syncPresence,
|
setPresence: syncPresence,
|
||||||
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
|
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
|
||||||
syncError = e;
|
syncError = e;
|
||||||
|
|
@ -1580,7 +1581,8 @@ class Client extends MatrixApi {
|
||||||
});
|
});
|
||||||
_currentSyncId = syncRequest.hashCode;
|
_currentSyncId = syncRequest.hashCode;
|
||||||
onSyncStatus.add(SyncStatusUpdate(SyncStatus.waitingForResponse));
|
onSyncStatus.add(SyncStatusUpdate(SyncStatus.waitingForResponse));
|
||||||
final syncResp = await syncRequest;
|
final syncResp =
|
||||||
|
await syncRequest.timeout(timeout + const Duration(seconds: 10));
|
||||||
onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing));
|
onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing));
|
||||||
if (syncResp == null) throw syncError ?? 'Unknown sync error';
|
if (syncResp == null) throw syncError ?? 'Unknown sync error';
|
||||||
if (_currentSyncId != syncRequest.hashCode) {
|
if (_currentSyncId != syncRequest.hashCode) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue