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

Be specific about which exceptions are retried (#16818)

parent a90a8504
...@@ -49,16 +49,27 @@ Future<StreamChannel<String>> _defaultOpenChannel(Uri uri) async { ...@@ -49,16 +49,27 @@ 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;
while (attempts < _kMaxAttempts && socket == null) {
attempts += 1; Future<void> onError(dynamic e) async {
try {
socket = await io.WebSocket.connect(uri.toString());
} catch (e) {
printTrace('Exception attempting to connect to observatory: $e'); printTrace('Exception attempting to connect to observatory: $e');
printTrace('This was attempt #$attempts. Will retry in $delay.'); printTrace('This was attempt #$attempts. Will retry in $delay.');
// Delay next attempt.
await new Future<Null>.delayed(delay); await new Future<Null>.delayed(delay);
// Back off exponentially.
delay *= 2; delay *= 2;
} }
while (attempts < _kMaxAttempts && socket == null) {
attempts += 1;
try {
socket = await io.WebSocket.connect(uri.toString());
} on io.WebSocketException catch (e) {
await onError(e);
} on io.SocketException catch (e) {
await onError(e);
}
} }
if (socket == null) { if (socket == null) {
......
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