@@ -154,7 +154,7 @@ class StreamingSyncImplementation {
154
154
155
155
// On error, wait a little before retrying
156
156
// When aborting, don't wait
157
- await Future . any ([ Future . delayed (retryDelay), _abort ! .onAbort] );
157
+ await _delayRetry ( );
158
158
}
159
159
}
160
160
} finally {
@@ -173,11 +173,9 @@ class StreamingSyncImplementation {
173
173
// This has the potential (in rare cases) to affect the crudThrottleTime,
174
174
// but it should not result in excessive uploads since the
175
175
// sync reconnects are also throttled.
176
+ // The stream here is closed on abort.
176
177
await for (var _ in mergeStreams (
177
178
[crudUpdateTriggerStream, _internalCrudTriggerController.stream])) {
178
- if (_abort? .aborted == true ) {
179
- break ;
180
- }
181
179
await uploadAllCrud ();
182
180
}
183
181
}
@@ -189,6 +187,13 @@ class StreamingSyncImplementation {
189
187
190
188
while (true ) {
191
189
try {
190
+ // It's possible that an abort or disconnect operation could
191
+ // be followed by a `close` operation. The close would cause these
192
+ // operations, which use the DB, to throw an exception. Breaking the loop
193
+ // here prevents unnecessary potential (caught) exceptions.
194
+ if (aborted) {
195
+ break ;
196
+ }
192
197
// This is the first item in the FIFO CRUD queue.
193
198
CrudEntry ? nextCrudItem = await adapter.nextCrudItem ();
194
199
if (nextCrudItem != null ) {
@@ -215,7 +220,7 @@ class StreamingSyncImplementation {
215
220
checkedCrudItem = null ;
216
221
isolateLogger.warning ('Data upload error' , e, stacktrace);
217
222
_updateStatus (uploading: false , uploadError: e);
218
- await Future . delayed (retryDelay );
223
+ await _delayRetry ( );
219
224
if (! isConnected) {
220
225
// Exit the upload loop if the sync stream is no longer connected
221
226
break ;
@@ -487,6 +492,12 @@ class StreamingSyncImplementation {
487
492
yield parseStreamingSyncLine (line as Map <String , dynamic >);
488
493
}
489
494
}
495
+
496
+ /// Delays the standard `retryDelay` Duration, but exists early if
497
+ /// an abort has been requested.
498
+ Future <void > _delayRetry () async {
499
+ await Future .any ([Future .delayed (retryDelay), _abort! .onAbort]);
500
+ }
490
501
}
491
502
492
503
/// Attempt to give a basic summary of the error for cases where the full error
0 commit comments