Unverified Commit ee735c4f authored by Yegor's avatar Yegor Committed by GitHub

Be specific about which exceptions are retried (#16818)

parent a90a8504
...@@ -49,15 +49,26 @@ Future<StreamChannel<String>> _defaultOpenChannel(Uri uri) async { ...@@ -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;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment