Skip to content

Commit 12bbaba

Browse files
authored
Do exponential backoff for all exceptions in VMService::defaultOpenChannel. (#16785)
We were trying to only catch WebSocketException, but in fact SocketException can be thrown as well.
1 parent 060a1ad commit 12bbaba

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/flutter_tools/lib/src/vmservice.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Future<StreamChannel<String>> _defaultOpenChannel(Uri uri) async {
5353
attempts += 1;
5454
try {
5555
socket = await io.WebSocket.connect(uri.toString());
56-
} on io.WebSocketException catch(e) {
56+
} catch (e) {
5757
printTrace('Exception attempting to connect to observatory: $e');
5858
printTrace('This was attempt #$attempts. Will retry in $delay.');
5959
await new Future<Null>.delayed(delay);

packages/flutter_tools/test/vmservice_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
import 'package:test/test.dart';
66

7-
import 'package:flutter_tools/src/base/io.dart';
87
import 'package:flutter_tools/src/base/port_scanner.dart';
98
import 'package:flutter_tools/src/vmservice.dart';
109

10+
import 'src/common.dart';
11+
import 'src/context.dart';
12+
1113
void main() {
1214
group('VMService', () {
13-
test('fails connection eagerly in the connect() method', () async {
15+
testUsingContext('fails connection eagerly in the connect() method', () async {
1416
final int port = await const HostPortScanner().findAvailablePort();
1517
expect(
1618
VMService.connect(Uri.parse('http://localhost:$port')),
17-
throwsA(const isInstanceOf<SocketException>()),
19+
throwsToolExit(),
1820
);
1921
});
2022
});

0 commit comments

Comments
 (0)