mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Be specific about which exceptions are retried (#16818)
This commit is contained in:
parent
a90a850462
commit
ee735c4f25
@ -49,15 +49,26 @@ Future<StreamChannel<String>> _defaultOpenChannel(Uri uri) async {
|
|||||||
Duration delay = const Duration(milliseconds: 100);
|
Duration delay = const Duration(milliseconds: 100);
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
io.WebSocket socket;
|
io.WebSocket socket;
|
||||||
|
|
||||||
|
Future<void> onError(dynamic e) async {
|
||||||
|
printTrace('Exception attempting to connect to observatory: $e');
|
||||||
|
printTrace('This was attempt #$attempts. Will retry in $delay.');
|
||||||
|
|
||||||
|
// Delay next attempt.
|
||||||
|
await new Future<Null>.delayed(delay);
|
||||||
|
|
||||||
|
// Back off exponentially.
|
||||||
|
delay *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
while (attempts < _kMaxAttempts && socket == null) {
|
while (attempts < _kMaxAttempts && socket == null) {
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
try {
|
try {
|
||||||
socket = await io.WebSocket.connect(uri.toString());
|
socket = await io.WebSocket.connect(uri.toString());
|
||||||
} catch (e) {
|
} on io.WebSocketException catch (e) {
|
||||||
printTrace('Exception attempting to connect to observatory: $e');
|
await onError(e);
|
||||||
printTrace('This was attempt #$attempts. Will retry in $delay.');
|
} on io.SocketException catch (e) {
|
||||||
await new Future<Null>.delayed(delay);
|
await onError(e);
|
||||||
delay *= 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user