Skip to content

Commit 75312ac

Browse files
committed
wip store: On non-transient request errors, reload rather than retry; TODO test
Hmm or maybe for those non-transient request errors we should stick with retrying? Maybe up to a bounded number of times? Those are by definition a bug either in the server or in our formulating the request: it's either a 4xx we didn't expect, or a malformed response (so in either case, a mismatch of our expectations to the server's behavior, and therefore a bug in one or the other), or something other than ApiRequestException entirely (and so a bug in the API request code). It's therefore hard to predict what's most likely to work. Maybe the most likely cause is that the server is having operational trouble that's not showing up as 5xx responses. We handle rate-limit errors separately, though, and make sure to back off if we get one of those. So this may not be a likely scenario. Also, when we abandon retrying getEvents and switch to re-register, we do end up backing off if that fails. It's just that that's a heavier request in the first place.
1 parent 347fca8 commit 75312ac

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

lib/model/store.dart

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -967,45 +967,29 @@ class UpdateMachine {
967967
if (_disposed) return;
968968

969969
store.isLoading = true;
970-
bool isUnexpected;
971970
bool shouldReportToUser;
972971
switch (e) {
973-
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
974-
rethrow;
975-
976972
case NetworkException(cause: SocketException()):
977973
// A [SocketException] is common when the app returns from sleep.
978-
isUnexpected = false;
979974
shouldReportToUser = false;
980975

981976
case NetworkException():
982977
case Server5xxException():
983-
isUnexpected = false;
984978
shouldReportToUser = true;
985979

986980
case ZulipApiException(httpStatus: 429):
987981
case ZulipApiException(code: 'RATE_LIMIT_HIT'):
988982
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
989-
isUnexpected = false;
990983
shouldReportToUser = true;
991984

992985
default:
993-
isUnexpected = true;
994-
shouldReportToUser = true;
986+
rethrow;
995987
}
996988

997-
if (isUnexpected) {
998-
assert(shouldReportToUser);
999-
assert(debugLog('Error polling event queue for $store: $e\n'
1000-
'Backing off and retrying even though may be hopeless…'));
1001-
// TODO(#186): Handle unrecoverable failures
1002-
_reportToUserErrorConnectingToServer(e);
1003-
} else {
1004-
assert(debugLog('Transient error polling event queue for $store: $e\n'
1005-
'Backing off, then will retry…'));
1006-
if (shouldReportToUser) {
1007-
maybeReportToUserTransientError(e);
1008-
}
989+
assert(debugLog('Transient error polling event queue for $store: $e\n'
990+
'Backing off, then will retry…'));
991+
if (shouldReportToUser) {
992+
maybeReportToUserTransientError(e);
1009993
}
1010994
await (backoffMachine ??= BackoffMachine()).wait();
1011995
if (_disposed) return;
@@ -1050,7 +1034,7 @@ class UpdateMachine {
10501034
}
10511035
}
10521036
} catch (e) {
1053-
// An error occurred, other than the request errors we retry on.
1037+
// An error occurred, other than the transient request errors we retry on.
10541038
// This means either a lost/expired event queue on the server (which is
10551039
// normal after the app is offline for a period like 10 minutes),
10561040
// or an unexpected exception representing a bug in our code or the server.
@@ -1084,6 +1068,8 @@ class UpdateMachine {
10841068
_reportToUserErrorConnectingToServer(e);
10851069
// Similar story to the _EventHandlingException case;
10861070
// separate only so that that other case can print more context.
1071+
// The bug here could be in the server if it's an ApiRequestException,
1072+
// but our remedy is the same either way.
10871073
}
10881074

10891075
// This disposes the store, which disposes this update machine.

0 commit comments

Comments
 (0)