Let a probe misfire not restart the stall detection

This commit is contained in:
Roland Geider
2026-08-15 20:16:06 +02:00
parent 9a97202dd4
commit 5e866de396
2 changed files with 27 additions and 2 deletions

View File

@@ -120,7 +120,9 @@ class SyncStreamWatchdog {
}
_offline = value;
if (value) {
_cancelTimer();
// A running timer deliberately survives: the probe misfires while a
// large download saturates the line, and cancelling here would let
// those misfires restart the detection over and over.
stalled.value = false;
}
}
@@ -143,6 +145,11 @@ class SyncStreamWatchdog {
void _onTimeout() {
_timer = null;
// Nothing to report while plain requests fail as well; the next status
// event re-arms once the backend answers again.
if (_offline) {
return;
}
stalled.value = true;
if (_lastError case final error?) {

View File

@@ -191,7 +191,25 @@ void main() {
});
});
test('going offline cancels a pending timer and clears the flag', () {
test('a probe misfiring under load does not restart the detection', () {
fakeAsync((async) {
// The reachability probe times out while a large download saturates
// the line and recovers right after. If that restarted the clock, the
// watchdog would never reach its timeout on exactly the connection it
// is meant to flag.
watchdog.onStatus(buildSyncStatus(connecting: true));
async.elapse(watchdog.timeout - const Duration(seconds: 10));
watchdog.offline = true;
watchdog.offline = false;
watchdog.onStatus(buildSyncStatus(connecting: true));
async.elapse(const Duration(seconds: 11));
expect(watchdog.stalled.value, isTrue);
});
});
test('going offline clears the flag and reports nothing further', () {
fakeAsync((async) {
watchdog.onStatus(buildSyncStatus(connecting: true));
async.elapse(watchdog.timeout);